Skip to content

Commit d342fcc

Browse files
committed
fix: patch for bookmarks
inspired by: diegomura/react-pdf#3113
1 parent 5e0a692 commit d342fcc

4 files changed

Lines changed: 38 additions & 73 deletions

File tree

patch/react-pdf.patch

Lines changed: 0 additions & 71 deletions
This file was deleted.

patches/@react-pdf__render.patch

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
diff --git a/lib/index.js b/lib/index.js
2+
index e4df914a22d4b13d26feb12ac0433c02f5861c12..3fc04e1b8a61b9c5910cfea10bc37e517dde6208 100644
3+
--- a/lib/index.js
4+
+++ b/lib/index.js
5+
@@ -2055,19 +2055,15 @@ const addNodeBookmark = (ctx, node, pageNumber, registry) => {
6+
return;
7+
node.children.forEach((child) => addNodeBookmark(ctx, child, pageNumber, registry));
8+
};
9+
-const addBookmarks = (ctx, root) => {
10+
- const registry = {};
11+
- const pages = root.children || [];
12+
- pages.forEach((page, i) => {
13+
- addNodeBookmark(ctx, page, i, registry);
14+
- });
15+
-};
16+
17+
const render = (ctx, doc) => {
18+
const pages = doc.children || [];
19+
const options = { imageCache: new Map(), fieldSets: [] };
20+
- pages.forEach((page) => renderNode(ctx, page, options));
21+
- addBookmarks(ctx, doc);
22+
+ const registry = {};
23+
+ pages.forEach((page, index) => {
24+
+ renderNode(ctx, page, options);
25+
+ addNodeBookmark(ctx, page, index, registry);
26+
+ });
27+
ctx.end();
28+
return ctx;
29+
};

pnpm-lock.yaml

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
patchedDependencies:
2+
'@react-pdf/render': patches/@react-pdf__render.patch

0 commit comments

Comments
 (0)