Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/docs/examples/copy-outline.js @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 // Copy an outline from one document to another PDF file. | |
| 2 // Can be used to transfer outlines when converting from another format into PDF. | |
| 3 // Can also be used to change outlines to use page numbers instead of named destinations. | |
| 4 | |
| 5 if (scriptArgs.length != 3) { | |
| 6 print("usage: mutool run copy-outline.js a.xps b.pdf output.pdf"); | |
| 7 quit(); | |
| 8 } | |
| 9 | |
| 10 function copy_outline_rec(cursor, input, list) { | |
| 11 list.forEach(function (node) { | |
| 12 var page = input.resolveLink(node.uri) | |
| 13 cursor.insert({ title: node.title, uri: "#page=" + (page + 1) }) | |
| 14 if (node.down) { | |
| 15 cursor.prev() | |
| 16 cursor.down() | |
| 17 copy_outline_rec(cursor, input, node.down) | |
| 18 cursor.up() | |
| 19 cursor.next() | |
| 20 } | |
| 21 }) | |
| 22 } | |
| 23 | |
| 24 function copy_outline(output, input, list) { | |
| 25 var cursor = output.outlineIterator() | |
| 26 while (cursor.item()) | |
| 27 cursor.delete() | |
| 28 copy_outline_rec(cursor, input, list) | |
| 29 } | |
| 30 | |
| 31 var input = mupdf.Document.openDocument(scriptArgs[0]) | |
| 32 var output = mupdf.Document.openDocument(scriptArgs[1]) | |
| 33 | |
| 34 copy_outline(output, input, input.loadOutline()) | |
| 35 | |
| 36 output.save(scriptArgs[2], "incremental"); |
