MCPcopy Index your code
hub / github.com/foliojs/pdfkit / finalize

Method finalize

lib/reference.js:45–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43 }
44
45 finalize() {
46 this.offset = this.document._offset;
47
48 const encryptFn = this.document._security
49 ? this.document._security.getEncryptFn(this.id, this.gen)
50 : null;
51
52 if (this.buffer.length) {
53 this.buffer = Buffer.concat(this.buffer);
54 if (this.compress) {
55 this.buffer = zlib.deflateSync(this.buffer);
56 }
57
58 if (encryptFn) {
59 this.buffer = encryptFn(this.buffer);
60 }
61
62 this.data.Length = this.buffer.length;
63 }
64
65 this.document._write(`${this.id} ${this.gen} obj`);
66 this.document._write(PDFObject.convert(this.data, encryptFn));
67
68 if (this.buffer.length) {
69 this.document._write('stream');
70 this.document._write(this.buffer);
71
72 this.buffer = []; // free up memory
73 this.document._write('\nendstream');
74 }
75
76 this.document._write('endobj');
77 this.document._refEnd(this);
78 }
79 toString() {
80 return `${this.id} ${this.gen} R`;
81 }

Callers 1

endMethod · 0.95

Calls 4

getEncryptFnMethod · 0.80
_writeMethod · 0.80
convertMethod · 0.80
_refEndMethod · 0.80

Tested by

no test coverage detected