comparison mupdf-source/docs/examples/jpx-to-pdf.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 // Script to create a PDF from JPEG2000 images.
2 // Each image be put on its own page.
3 // This script can be used to create files to test JPEG2000 support in PDF viewers.
4
5 var doc = new PDFDocument();
6
7 function addJPXImage(filename, w, h) {
8 return doc.addRawStream(
9 readFile(filename),
10 {
11 Type: "XObject",
12 Subtype: "Image",
13 Width: w,
14 Height: h,
15 Filter: "JPXDecode"
16 }
17 );
18 }
19
20 function addJPXPage(filename) {
21 var image = new Image(filename);
22 var w = image.getWidth();
23 var h = image.getHeight();
24 var mediabox = [0, 0, w, h];
25 var resources = { XObject: { I: addJPXImage(filename, w, h) } };
26 var contents = "q " + w + " 0 0 " + h + " 0 0 cm /I Do Q";
27 doc.insertPage(-1, doc.addPage(mediabox, 0, resources, contents));
28 }
29
30 var i, n = scriptArgs.length;
31 if (n < 1) {
32 print("usage: mutool run jpx-to-pdf.js file.jpx ...");
33 quit();
34 }
35 for (i = 0; i < n; ++i) {
36 addJPXPage(scriptArgs[i]);
37 }
38
39 doc.save("out.pdf", "ascii,pretty");