comparison 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
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
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")