| 26 | |
| 27 | class PDFDocument extends stream.Readable { |
| 28 | constructor(options = {}) { |
| 29 | super(options); |
| 30 | this.options = options; |
| 31 | |
| 32 | // PDF version |
| 33 | switch (options.pdfVersion) { |
| 34 | case '1.4': |
| 35 | this.version = 1.4; |
| 36 | break; |
| 37 | case '1.5': |
| 38 | this.version = 1.5; |
| 39 | break; |
| 40 | case '1.6': |
| 41 | this.version = 1.6; |
| 42 | break; |
| 43 | case '1.7': |
| 44 | case '1.7ext3': |
| 45 | this.version = 1.7; |
| 46 | break; |
| 47 | default: |
| 48 | this.version = 1.3; |
| 49 | break; |
| 50 | } |
| 51 | |
| 52 | // Whether streams should be compressed |
| 53 | this.compress = |
| 54 | this.options.compress != null ? this.options.compress : true; |
| 55 | |
| 56 | this._pageBuffer = []; |
| 57 | this._pageBufferStart = 0; |
| 58 | |
| 59 | // The PDF object store |
| 60 | this._offsets = []; |
| 61 | this._waiting = 0; |
| 62 | this._ended = false; |
| 63 | this._offset = 0; |
| 64 | const Pages = this.ref({ |
| 65 | Type: 'Pages', |
| 66 | Count: 0, |
| 67 | Kids: [], |
| 68 | }); |
| 69 | |
| 70 | const Names = this.ref({ |
| 71 | Dests: new PDFNameTree(), |
| 72 | }); |
| 73 | |
| 74 | this._root = this.ref({ |
| 75 | Type: 'Catalog', |
| 76 | Pages, |
| 77 | Names, |
| 78 | }); |
| 79 | |
| 80 | if (this.options.lang) { |
| 81 | this._root.data.Lang = new String(this.options.lang); |
| 82 | } |
| 83 | |
| 84 | if (this.options.pageLayout) { |
| 85 | const layout = this.options.pageLayout; |