Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/docs/examples/import-fdf.js @ 3:2c135c81b16c
MERGE: upstream PyMuPDF 1.26.4 with MuPDF 1.26.7
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:44:09 +0200 |
| parents | b50eed0cc0ef |
| children |
comparison
equal
deleted
inserted
replaced
| 0:6015a75abc2d | 3:2c135c81b16c |
|---|---|
| 1 // usage: mutool run import-fdf.js input.pdf data.fdf output.pdf | |
| 2 // | |
| 3 // Import annotations from FDF into PDF file. | |
| 4 // | |
| 5 // TODO: import form data! | |
| 6 | |
| 7 "use strict" | |
| 8 | |
| 9 if (scriptArgs.length != 3) { | |
| 10 print("usage: mutool run import-fdf.js file.pdf data.fdf output.pdf") | |
| 11 quit() | |
| 12 } | |
| 13 | |
| 14 var doc = mupdf.Document.openDocument(scriptArgs[0]) | |
| 15 var data = mupdf.Document.openDocument(scriptArgs[1]) | |
| 16 var map = doc.newGraftMap() | |
| 17 | |
| 18 var annots = data.getTrailer().Root.FDF.Annots | |
| 19 if (annots) { | |
| 20 annots.forEach( | |
| 21 function (annot) { | |
| 22 var ref = map.graftObject(annot) | |
| 23 var page = doc.findPage(ref.Page) | |
| 24 if (!page.Annots) | |
| 25 page.Annots = [] | |
| 26 page.Annots.push(ref) | |
| 27 ref.P = page | |
| 28 ref.delete("Page") | |
| 29 } | |
| 30 ) | |
| 31 } | |
| 32 | |
| 33 doc.save(scriptArgs[2], "incremental") |
