| 67 | } |
| 68 | |
| 69 | finalize() { |
| 70 | this.offset = this.document._offset; |
| 71 | |
| 72 | this.document._write(`${this.id} ${this.gen} obj`); |
| 73 | this.document._write(PDFObject.convert(this.data)); |
| 74 | |
| 75 | if (this.chunks.length) { |
| 76 | this.document._write('stream'); |
| 77 | for (let chunk of Array.from(this.chunks)) { |
| 78 | this.document._write(chunk); |
| 79 | } |
| 80 | |
| 81 | this.chunks.length = 0; // free up memory |
| 82 | this.document._write('\nendstream'); |
| 83 | } |
| 84 | |
| 85 | this.document._write('endobj'); |
| 86 | return this.document._refEnd(this); |
| 87 | } |
| 88 | |
| 89 | toString() { |
| 90 | return `${this.id} ${this.gen} R`; |