Mercurial > hgrepos > Python2 > PyMuPDF
diff mupdf-source/docs/examples/import-fdf.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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mupdf-source/docs/examples/import-fdf.js Mon Sep 15 11:43:07 2025 +0200 @@ -0,0 +1,33 @@ +// usage: mutool run import-fdf.js input.pdf data.fdf output.pdf +// +// Import annotations from FDF into PDF file. +// +// TODO: import form data! + +"use strict" + +if (scriptArgs.length != 3) { + print("usage: mutool run import-fdf.js file.pdf data.fdf output.pdf") + quit() +} + +var doc = mupdf.Document.openDocument(scriptArgs[0]) +var data = mupdf.Document.openDocument(scriptArgs[1]) +var map = doc.newGraftMap() + +var annots = data.getTrailer().Root.FDF.Annots +if (annots) { + annots.forEach( + function (annot) { + var ref = map.graftObject(annot) + var page = doc.findPage(ref.Page) + if (!page.Annots) + page.Annots = [] + page.Annots.push(ref) + ref.P = page + ref.delete("Page") + } + ) +} + +doc.save(scriptArgs[2], "incremental")
