浏览代码

Set page size in CSS

crobi 10 年前
父节点
当前提交
040f8377ee
共有 3 个文件被更改,包括 43 次插入20 次删除
  1. 11
    18
      generator/css/card-size.css
  2. 4
    0
      generator/css/output.css
  3. 28
    2
      generator/js/cards.js

+ 11
- 18
generator/css/card-size.css 查看文件

12
     3) Fill each page with cards, arranged around the center of the page.
12
     3) Fill each page with cards, arranged around the center of the page.
13
 */
13
 */
14
 
14
 
15
-/* Remove page margins */
16
-@page {
17
-    margin: 0;
18
-    padding: 0;
19
-}
20
 
15
 
21
 /* Center all content within a page */
16
 /* Center all content within a page */
22
 .page {
17
 .page {
26
     flex-direction: row;
21
     flex-direction: row;
27
     flex-wrap: wrap;
22
     flex-wrap: wrap;
28
     page-break-after: always;
23
     page-break-after: always;
29
-    padding: 0mm;
24
+    padding: 0;
30
 }
25
 }
31
 
26
 
32
-/* A4 paper area (minus epsilon for rounding) */
27
+/* A4 paper area */
28
+/* Chrome has problems with page sizes given in metric units. Make the paper area slightly smaller to work around this. */
33
 page[size="A4"] {
29
 page[size="A4"] {
34
-    width:  209mm; /* full: 210.0mm */
35
-    height: 295mm; /* full: 297.0mm */
30
+    width:  210mm; /* full: 210.0mm */
31
+    height: 296mm; /* full: 297.0mm */
36
 }
32
 }
37
 
33
 
38
-/* US letter area (minus epsilon for rounding) */
34
+/* US letter area */
39
 page[size="Letter"] {
35
 page[size="Letter"] {
40
-    width:  215mm; /* full: 215.9mm (8.5in) */
41
-    height: 278mm; /* full: 279.4mm (11.0in) */
36
+    width:  8.5in;
37
+    height: 11.0in;
42
 }
38
 }
43
 
39
 
44
 page[size="25x35"] {
40
 page[size="25x35"] {
45
-    width: 63.6mm;
46
-    height: 89.0mm;
41
+    width: 2.5in;
42
+    height: 3.5in;
47
 }
43
 }
48
 
44
 
49
 /* Default card size */
45
 /* Default card size */
50
 .card {
46
 .card {
51
     width:2.5in;
47
     width:2.5in;
52
-    min-width:2.5in;
53
     height:3.5in;
48
     height:3.5in;
54
 }
49
 }
55
 
50
 
56
 /* Bridge card size */
51
 /* Bridge card size */
57
 .card-size-225x35 {
52
 .card-size-225x35 {
58
     width:2.25in;
53
     width:2.25in;
59
-    min-width:2.25in;
60
     height:3.5in;
54
     height:3.5in;
61
 }
55
 }
62
 .card-size-225x35 .card-back-icon {
56
 .card-size-225x35 .card-back-icon {
67
 /* Poker / Magic card size */
61
 /* Poker / Magic card size */
68
 .card-size-25x35 {
62
 .card-size-25x35 {
69
     width:2.5in;
63
     width:2.5in;
70
-    min-width:2.5in;
71
     height:3.5in;
64
     height:3.5in;
72
 }
65
 }
73
 .card-size-25x35 .card-back-icon {
66
 .card-size-25x35 .card-back-icon {
89
 /* Landscape big card */
82
 /* Landscape big card */
90
 .card-size-75x50 {
83
 .card-size-75x50 {
91
     width:7.5in;
84
     width:7.5in;
92
-    min-width:7.5in;
93
     height:5.0in;
85
     height:5.0in;
94
 }
86
 }
95
 .card-size-75x50 .card-back-icon {
87
 .card-size-75x50 .card-back-icon {
97
     height: 2in;
89
     height: 2in;
98
 }
90
 }
99
 
91
 
92
+/* Card sizes that fill out the entire sheet of paper (minimal margins) */
100
 .page[size="A4"] .card-size-full3x3 {
93
 .page[size="A4"] .card-size-full3x3 {
101
     width:69mm;
94
     width:69mm;
102
     height:98mm;
95
     height:98mm;

+ 4
- 0
generator/css/output.css 查看文件

18
 @media print {
18
 @media print {
19
   .page-preview {
19
   .page-preview {
20
     margin: 0;
20
     margin: 0;
21
+    padding: 0;
22
+    border: 0;
21
     box-shadow: 0;
23
     box-shadow: 0;
22
     background-color: white;
24
     background-color: white;
23
   }
25
   }
24
   .page-background {
26
   .page-background {
25
     margin: 0;
27
     margin: 0;
28
+    padding: 0;
29
+    border: 0;
26
     box-shadow: 0;
30
     box-shadow: 0;
27
     /* Set the background to gray to visualize the page size in the print preview */
31
     /* Set the background to gray to visualize the page size in the print preview */
28
     background-color: gray;
32
     background-color: gray;

+ 28
- 2
generator/js/cards.js 查看文件

309
     return result;
309
     return result;
310
 }
310
 }
311
 
311
 
312
+function card_pages_generate_style(options) {
313
+    var size = "a4";
314
+    switch (options.page_size) {
315
+        case "A3": size = "A3 portrait"; break;
316
+        case "A4": size = "210mm 297mm"; break;
317
+        case "A5": size = "A5 portrait"; break;
318
+        case "Letter": size = "letter portrait"; break;
319
+        case "25x35": size = "2.5in 3.5in"; break;
320
+        default: size = "auto";
321
+    }
322
+
323
+    var result = "";
324
+    result += "<style>\n";
325
+    result += "@page {\n";
326
+    result += "    margin: 0;\n";
327
+    result += "    size:" + size + ";\n";
328
+    result += "    -webkit-print-color-adjust: exact;\n";
329
+    result += "}\n";
330
+    result += "</style>\n";
331
+    return result;
332
+}
333
+
312
 function card_pages_generate_html(card_data, options) {
334
 function card_pages_generate_html(card_data, options) {
313
     options = options || card_default_options();
335
     options = options || card_default_options();
314
     var rows = options.page_rows || 3;
336
     var rows = options.page_rows || 3;
351
         pages = card_pages_split(cards, rows, cols);
373
         pages = card_pages_split(cards, rows, cols);
352
     }
374
     }
353
 
375
 
354
-    // Wrap all pages in a <page> element
355
-    return card_pages_wrap(pages, options);
376
+    // Wrap all pages in a <page> element and add CSS for the page size
377
+    var result = "";
378
+    result += card_pages_generate_style(options);
379
+    result += card_pages_wrap(pages, options);
380
+
381
+    return result;
356
 }
382
 }
357
 
383
 
358
 function card_pages_insert_into(card_data, container) {
384
 function card_pages_insert_into(card_data, container) {

正在加载...
取消
保存