Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/stale-toys-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-pdf/pdfkit": patch
---

Add back functionality for bookmark props
4 changes: 3 additions & 1 deletion packages/pdfkit/src/mixins/outline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}
}
};
38 changes: 34 additions & 4 deletions packages/pdfkit/src/outline.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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);
Expand Down