diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mupdf-source/docs/examples/jpx-to-pdf.js	Mon Sep 15 11:43:07 2025 +0200
@@ -0,0 +1,39 @@
+// Script to create a PDF from JPEG2000 images.
+// Each image be put on its own page.
+// This script can be used to create files to test JPEG2000 support in PDF viewers.
+
+var doc = new PDFDocument();
+
+function addJPXImage(filename, w, h) {
+	return doc.addRawStream(
+		readFile(filename),
+		{
+			Type: "XObject",
+			Subtype: "Image",
+			Width: w,
+			Height: h,
+			Filter: "JPXDecode"
+		}
+	);
+}
+
+function addJPXPage(filename) {
+	var image = new Image(filename);
+	var w = image.getWidth();
+	var h = image.getHeight();
+	var mediabox = [0, 0, w, h];
+	var resources = { XObject: { I: addJPXImage(filename, w, h) } };
+	var contents = "q " + w + " 0 0 " + h + " 0 0 cm /I Do Q";
+	doc.insertPage(-1, doc.addPage(mediabox, 0, resources, contents));
+}
+
+var i, n = scriptArgs.length;
+if (n < 1) {
+	print("usage: mutool run jpx-to-pdf.js file.jpx ...");
+	quit();
+}
+for (i = 0; i < n; ++i) {
+	addJPXPage(scriptArgs[i]);
+}
+
+doc.save("out.pdf", "ascii,pretty");