summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-04-10 13:27:57 +0200
committerTor Andersson <tor.andersson@artifex.com>2017-04-13 14:13:31 +0200
commitee39a8939ee668ee192313ed32eae53f6c2bc427 (patch)
tree45b7784f93bee959254c6767799566c3dbd8a07f /docs
parent708cf16d9259392dab17bdb1eeaefa21baa5a7fe (diff)
downloadmupdf-ee39a8939ee668ee192313ed32eae53f6c2bc427.tar.xz
Add an example JPEG2000 to PDF script.
Diffstat (limited to 'docs')
-rw-r--r--docs/examples/jpx-to-pdf.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/docs/examples/jpx-to-pdf.js b/docs/examples/jpx-to-pdf.js
new file mode 100644
index 00000000..ee95ab30
--- /dev/null
+++ b/docs/examples/jpx-to-pdf.js
@@ -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 = argv.length;
+if (n < 2) {
+ print("usage: mutool run jpx-to-pdf.js file.jpx ...");
+ quit();
+}
+for (i = 1; i < n; ++i) {
+ addJPXPage(argv[i]);
+}
+
+doc.save("out.pdf", "ascii,pretty");