Remove setTimeout call in PDFReference.finalize

This commit is contained in:
Luiz Américo 2018-12-21 20:33:14 -03:00
parent 56d4327181
commit 4e90b87d82

View File

@ -42,39 +42,36 @@ class PDFReference extends PDFAbstractReference {
}
finalize() {
return setTimeout(() => {
this.offset = this.document._offset;
this.offset = this.document._offset;
const encryptFn = this.document._security ? this.document._security.getEncryptFn(this.id, this.gen) : null;
const encryptFn = this.document._security ? this.document._security.getEncryptFn(this.id, this.gen) : null;
if (this.buffer.length) {
this.buffer = Buffer.concat(this.buffer);
if (this.compress) {
this.buffer = zlib.deflateSync(this.buffer);
}
if (encryptFn) {
this.buffer = encryptFn(this.buffer);
}
this.data.Length = this.buffer.length;
if (this.buffer.length) {
this.buffer = Buffer.concat(this.buffer);
if (this.compress) {
this.buffer = zlib.deflateSync(this.buffer);
}
this.document._write(`${this.id} ${this.gen} obj`);
this.document._write(PDFObject.convert(this.data, encryptFn));
if (this.buffer.length) {
this.document._write('stream');
this.document._write(this.buffer);
this.buffer = []; // free up memory
this.document._write('\nendstream');
if (encryptFn) {
this.buffer = encryptFn(this.buffer);
}
this.document._write('endobj');
return this.document._refEnd(this);
this.data.Length = this.buffer.length;
}
, 0);
this.document._write(`${this.id} ${this.gen} obj`);
this.document._write(PDFObject.convert(this.data, encryptFn));
if (this.buffer.length) {
this.document._write('stream');
this.document._write(this.buffer);
this.buffer = []; // free up memory
this.document._write('\nendstream');
}
this.document._write('endobj');
this.document._refEnd(this);
}
toString() {
return `${this.id} ${this.gen} R`;