1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | (function() {
|
8 | var PDFPage;
|
9 |
|
10 | PDFPage = (function() {
|
11 | var DEFAULT_MARGINS, SIZES;
|
12 |
|
13 | function PDFPage(document, options) {
|
14 | var dimensions;
|
15 | this.document = document;
|
16 | if (options == null) {
|
17 | options = {};
|
18 | }
|
19 | this.size = options.size || 'letter';
|
20 | this.layout = options.layout || 'portrait';
|
21 | if (typeof options.margin === 'number') {
|
22 | this.margins = {
|
23 | top: options.margin,
|
24 | left: options.margin,
|
25 | bottom: options.margin,
|
26 | right: options.margin
|
27 | };
|
28 | } else {
|
29 | this.margins = options.margins || DEFAULT_MARGINS;
|
30 | }
|
31 | dimensions = Array.isArray(this.size) ? this.size : SIZES[this.size.toUpperCase()];
|
32 | this.width = dimensions[this.layout === 'portrait' ? 0 : 1];
|
33 | this.height = dimensions[this.layout === 'portrait' ? 1 : 0];
|
34 | this.content = this.document.ref();
|
35 | this.resources = this.document.ref({
|
36 | ProcSet: ['PDF', 'Text', 'ImageB', 'ImageC', 'ImageI']
|
37 | });
|
38 | Object.defineProperties(this, {
|
39 | fonts: {
|
40 | get: (function(_this) {
|
41 | return function() {
|
42 | var base;
|
43 | return (base = _this.resources.data).Font != null ? base.Font : base.Font = {};
|
44 | };
|
45 | })(this)
|
46 | },
|
47 | xobjects: {
|
48 | get: (function(_this) {
|
49 | return function() {
|
50 | var base;
|
51 | return (base = _this.resources.data).XObject != null ? base.XObject : base.XObject = {};
|
52 | };
|
53 | })(this)
|
54 | },
|
55 | ext_gstates: {
|
56 | get: (function(_this) {
|
57 | return function() {
|
58 | var base;
|
59 | return (base = _this.resources.data).ExtGState != null ? base.ExtGState : base.ExtGState = {};
|
60 | };
|
61 | })(this)
|
62 | },
|
63 | patterns: {
|
64 | get: (function(_this) {
|
65 | return function() {
|
66 | var base;
|
67 | return (base = _this.resources.data).Pattern != null ? base.Pattern : base.Pattern = {};
|
68 | };
|
69 | })(this)
|
70 | },
|
71 | annotations: {
|
72 | get: (function(_this) {
|
73 | return function() {
|
74 | var base;
|
75 | return (base = _this.dictionary.data).Annots != null ? base.Annots : base.Annots = [];
|
76 | };
|
77 | })(this)
|
78 | }
|
79 | });
|
80 | this.dictionary = this.document.ref({
|
81 | Type: 'Page',
|
82 | Parent: this.document._root.data.Pages,
|
83 | MediaBox: [0, 0, this.width, this.height],
|
84 | Contents: this.content,
|
85 | Resources: this.resources
|
86 | });
|
87 | }
|
88 |
|
89 | PDFPage.prototype.maxY = function() {
|
90 | return this.height - this.margins.bottom;
|
91 | };
|
92 |
|
93 | PDFPage.prototype.write = function(chunk) {
|
94 | return this.content.write(chunk);
|
95 | };
|
96 |
|
97 | PDFPage.prototype.end = function() {
|
98 | this.dictionary.end();
|
99 | this.resources.end();
|
100 | return this.content.end();
|
101 | };
|
102 |
|
103 | DEFAULT_MARGINS = {
|
104 | top: 72,
|
105 | left: 72,
|
106 | bottom: 72,
|
107 | right: 72
|
108 | };
|
109 |
|
110 | SIZES = {
|
111 | '4A0': [4767.87, 6740.79],
|
112 | '2A0': [3370.39, 4767.87],
|
113 | A0: [2383.94, 3370.39],
|
114 | A1: [1683.78, 2383.94],
|
115 | A2: [1190.55, 1683.78],
|
116 | A3: [841.89, 1190.55],
|
117 | A4: [595.28, 841.89],
|
118 | A5: [419.53, 595.28],
|
119 | A6: [297.64, 419.53],
|
120 | A7: [209.76, 297.64],
|
121 | A8: [147.40, 209.76],
|
122 | A9: [104.88, 147.40],
|
123 | A10: [73.70, 104.88],
|
124 | B0: [2834.65, 4008.19],
|
125 | B1: [2004.09, 2834.65],
|
126 | B2: [1417.32, 2004.09],
|
127 | B3: [1000.63, 1417.32],
|
128 | B4: [708.66, 1000.63],
|
129 | B5: [498.90, 708.66],
|
130 | B6: [354.33, 498.90],
|
131 | B7: [249.45, 354.33],
|
132 | B8: [175.75, 249.45],
|
133 | B9: [124.72, 175.75],
|
134 | B10: [87.87, 124.72],
|
135 | C0: [2599.37, 3676.54],
|
136 | C1: [1836.85, 2599.37],
|
137 | C2: [1298.27, 1836.85],
|
138 | C3: [918.43, 1298.27],
|
139 | C4: [649.13, 918.43],
|
140 | C5: [459.21, 649.13],
|
141 | C6: [323.15, 459.21],
|
142 | C7: [229.61, 323.15],
|
143 | C8: [161.57, 229.61],
|
144 | C9: [113.39, 161.57],
|
145 | C10: [79.37, 113.39],
|
146 | RA0: [2437.80, 3458.27],
|
147 | RA1: [1729.13, 2437.80],
|
148 | RA2: [1218.90, 1729.13],
|
149 | RA3: [864.57, 1218.90],
|
150 | RA4: [609.45, 864.57],
|
151 | SRA0: [2551.18, 3628.35],
|
152 | SRA1: [1814.17, 2551.18],
|
153 | SRA2: [1275.59, 1814.17],
|
154 | SRA3: [907.09, 1275.59],
|
155 | SRA4: [637.80, 907.09],
|
156 | EXECUTIVE: [521.86, 756.00],
|
157 | FOLIO: [612.00, 936.00],
|
158 | LEGAL: [612.00, 1008.00],
|
159 | LETTER: [612.00, 792.00],
|
160 | TABLOID: [792.00, 1224.00]
|
161 | };
|
162 |
|
163 | return PDFPage;
|
164 |
|
165 | })();
|
166 |
|
167 | module.exports = PDFPage;
|
168 |
|
169 | }).call(this);
|