Kaynağa Gözat

Set page size in CSS

crobi 10 yıl önce
ebeveyn
işleme
040f8377ee
3 değiştirilmiş dosya ile 43 ekleme ve 20 silme
  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 Dosyayı Görüntüle

@@ -12,11 +12,6 @@
12 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 16
 /* Center all content within a page */
22 17
 .page {
@@ -26,37 +21,36 @@
26 21
     flex-direction: row;
27 22
     flex-wrap: wrap;
28 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 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 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 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 45
 /* Default card size */
50 46
 .card {
51 47
     width:2.5in;
52
-    min-width:2.5in;
53 48
     height:3.5in;
54 49
 }
55 50
 
56 51
 /* Bridge card size */
57 52
 .card-size-225x35 {
58 53
     width:2.25in;
59
-    min-width:2.25in;
60 54
     height:3.5in;
61 55
 }
62 56
 .card-size-225x35 .card-back-icon {
@@ -67,7 +61,6 @@ page[size="25x35"] {
67 61
 /* Poker / Magic card size */
68 62
 .card-size-25x35 {
69 63
     width:2.5in;
70
-    min-width:2.5in;
71 64
     height:3.5in;
72 65
 }
73 66
 .card-size-25x35 .card-back-icon {
@@ -89,7 +82,6 @@ page[size="25x35"] {
89 82
 /* Landscape big card */
90 83
 .card-size-75x50 {
91 84
     width:7.5in;
92
-    min-width:7.5in;
93 85
     height:5.0in;
94 86
 }
95 87
 .card-size-75x50 .card-back-icon {
@@ -97,6 +89,7 @@ page[size="25x35"] {
97 89
     height: 2in;
98 90
 }
99 91
 
92
+/* Card sizes that fill out the entire sheet of paper (minimal margins) */
100 93
 .page[size="A4"] .card-size-full3x3 {
101 94
     width:69mm;
102 95
     height:98mm;

+ 4
- 0
generator/css/output.css Dosyayı Görüntüle

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

+ 28
- 2
generator/js/cards.js Dosyayı Görüntüle

@@ -309,6 +309,28 @@ function card_pages_wrap(pages, options) {
309 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 334
 function card_pages_generate_html(card_data, options) {
313 335
     options = options || card_default_options();
314 336
     var rows = options.page_rows || 3;
@@ -351,8 +373,12 @@ function card_pages_generate_html(card_data, options) {
351 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 384
 function card_pages_insert_into(card_data, container) {

Loading…
İptal
Kaydet