Commit 4c55b7d
committed
fix: bookmarks.js silently destroyed a PDF's existing bookmarks when adding a new one
Add Bookmarks always rebuilt /Outlines from scratch containing only what the
user typed in the current session, never reading the PDF's own pre-existing
outline first. A user adding one bookmark to an already-bookmarked PDF (e.g.
a Word/InDesign export with a heading-based TOC) silently lost every existing
bookmark in the output, with zero warning.
Fixed by reading the source PDF's top-level /Outlines linked list at load
time (same resolution logic as split-by-bookmarks.js's readTopLevelOutline)
and pre-populating the bookmarks queue with it, so existing entries are
preserved unless the user explicitly removes them via the same Remove button
used for newly-added ones. Verified against the real vendored pdf-lib.js:
reproduced the original bug (2 existing bookmarks -> 1 after adding one new
one), then confirmed the fix (3 bookmarks survive), plus a no-existing-outline
PDF still loads with an empty queue and no throw.
Also reworded the success message from "N bookmark(s) added" to "N bookmark(s)
saved", since the count can now include preserved pre-existing entries, not
just ones typed this session.1 parent 8933fb2 commit 4c55b7d
1 file changed
Lines changed: 48 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
105 | 151 | | |
106 | 152 | | |
107 | 153 | | |
108 | 154 | | |
109 | 155 | | |
110 | 156 | | |
111 | | - | |
| 157 | + | |
112 | 158 | | |
113 | 159 | | |
114 | 160 | | |
| |||
291 | 337 | | |
292 | 338 | | |
293 | 339 | | |
294 | | - | |
| 340 | + | |
295 | 341 | | |
296 | 342 | | |
297 | 343 | | |
| |||
0 commit comments