Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate the document's ID on demand instead of the class constructor #2814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/pdfkit/src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ class PDFDocument extends stream.Readable {
});
}

// Generate file ID
this._id = PDFSecurity.generateFileID(this.info);

// Initialize security settings
// this._security = PDFSecurity.create(this, options);

Expand All @@ -133,6 +130,10 @@ class PDFDocument extends stream.Readable {
}
}

_id() {
return PDFSecurity.generateFileID(this.info);
}

addPage(options) {
// end the current page if needed
if (options == null) {
Expand Down Expand Up @@ -300,11 +301,12 @@ class PDFDocument extends stream.Readable {
}

// trailer
const id = this._id();
const trailer = {
Size: this._offsets.length + 1,
Root: this._root,
Info: this._info,
ID: [this._id, this._id]
ID: [id, id]
};

// if (this._security) {
Expand Down