From 804871667610e880ee68b83d11e1b6783def6e04 Mon Sep 17 00:00:00 2001 From: Mike Molisani Date: Fri, 12 Apr 2024 11:02:30 -0400 Subject: [PATCH 1/2] Add back functionality for bookmark props --- packages/pdfkit/src/mixins/outline.js | 4 ++- packages/pdfkit/src/outline.js | 38 ++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/packages/pdfkit/src/mixins/outline.js b/packages/pdfkit/src/mixins/outline.js index 1da603e40..eabfd5283 100644 --- a/packages/pdfkit/src/mixins/outline.js +++ b/packages/pdfkit/src/mixins/outline.js @@ -9,7 +9,9 @@ export default { this.outline.endOutline(); if (this.outline.children.length > 0) { this._root.data.Outlines = this.outline.dictionary; - return (this._root.data.PageMode = 'UseOutlines'); + /* Custom fork start */ + return (this._root.data.PageMode = this._root.data.PageMode || 'UseOutlines'); + /* Custom fork end */ } } }; diff --git a/packages/pdfkit/src/outline.js b/packages/pdfkit/src/outline.js index 8dc709d21..26f0abd64 100644 --- a/packages/pdfkit/src/outline.js +++ b/packages/pdfkit/src/outline.js @@ -1,11 +1,32 @@ +/* Custom fork start */ +const DEFAULT_OPTIONS = { + top: 0, + left: 0, + zoom: 0, + fit: false, + pageNumber: null, + expanded: false +}; +/* Custom fork end */ + class PDFOutline { - constructor(document, parent, title, dest, options = { expanded: false }) { + constructor(document, parent, title, dest, options = DEFAULT_OPTIONS) { this.document = document; this.options = options; this.outlineData = {}; if (dest !== null) { - this.outlineData['Dest'] = [dest.dictionary, 'Fit']; + /* Custom fork start */ + const destWidth = dest.data.MediaBox[2]; + const destHeight = dest.data.MediaBox[3]; + const top = destHeight - (options.top || 0); + const left = destWidth - (options.left || 0); + const zoom = options.zoom || 0; + + this.outlineData['Dest'] = options.fit + ? [dest, 'Fit'] + : [dest, 'XYZ', left, top, zoom]; + /* Custom fork end */ } if (parent !== null) { @@ -20,12 +41,21 @@ class PDFOutline { this.children = []; } - addItem(title, options = { expanded: false }) { + addItem(title, options = DEFAULT_OPTIONS) { + /* Custom fork start */ + const pages = this.document._root.data.Pages.data.Kids; + + const dest = + options.pageNumber !== null + ? pages[options.pageNumber] + : this.document.page.dictionary; + /* Custom fork end */ + const result = new PDFOutline( this.document, this.dictionary, title, - this.document.page, + dest, options ); this.children.push(result); From e993f89d78d021b9e61b99aa7ca3d81c252c47a0 Mon Sep 17 00:00:00 2001 From: Diego Muracciole Date: Tue, 23 Sep 2025 22:56:08 +0200 Subject: [PATCH 2/2] Create stale-toys-tickle.md --- .changeset/stale-toys-tickle.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/stale-toys-tickle.md diff --git a/.changeset/stale-toys-tickle.md b/.changeset/stale-toys-tickle.md new file mode 100644 index 000000000..7d944270a --- /dev/null +++ b/.changeset/stale-toys-tickle.md @@ -0,0 +1,5 @@ +--- +"@react-pdf/pdfkit": patch +--- + +Add back functionality for bookmark props