summaryrefslogtreecommitdiff
path: root/docs/mutool
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-04-07 16:16:56 +0200
committerTor Andersson <tor.andersson@artifex.com>2017-04-13 13:16:21 +0200
commit9c805cc9f934cd12e89014db8ad70e3191cdaf2d (patch)
tree5aece10eaccc25d060b2803c4d201341048caf96 /docs/mutool
parent49d5a9856020627af1fc4063ff5a26b26e9270cf (diff)
downloadmupdf-9c805cc9f934cd12e89014db8ad70e3191cdaf2d.tar.xz
Move all examples to docs/examples directory.
Diffstat (limited to 'docs/mutool')
-rw-r--r--docs/mutool/examples/create-thumbnail.js19
-rw-r--r--docs/mutool/examples/draw-device.js45
-rw-r--r--docs/mutool/examples/draw-document.js9
-rw-r--r--docs/mutool/examples/pdf-create-lowlevel.js63
-rw-r--r--docs/mutool/examples/pdf-create.js35
-rw-r--r--docs/mutool/examples/pdf-merge.js67
-rw-r--r--docs/mutool/examples/trace-device.js102
7 files changed, 0 insertions, 340 deletions
diff --git a/docs/mutool/examples/create-thumbnail.js b/docs/mutool/examples/create-thumbnail.js
deleted file mode 100644
index 120a8e88..00000000
--- a/docs/mutool/examples/create-thumbnail.js
+++ /dev/null
@@ -1,19 +0,0 @@
-// Create a PDF containing thumbnails of pages rendered from another PDF.
-
-var pdf = new PDFDocument()
-
-var subdoc = new Document("pdfref17.pdf")
-
-var resources = { XObject: {} }
-
-var contents = new Buffer()
-for (var i=0; i < 5; ++i) {
- var pixmap = subdoc.loadPage(1140+i).toPixmap([0.2,0,0,0.2,0,0], DeviceRGB, true)
- resources.XObject["Im" + i] = pdf.addImage(new Image(pixmap))
- contents.writeLine("q 100 0 0 150 " + (50+100*i) + " 50 cm /Im" + i + " Do Q")
-}
-
-var page = pdf.addPage([0,0,100+i*100,250], 0, resources, contents)
-pdf.insertPage(-1, page)
-
-pdf.save("out.pdf")
diff --git a/docs/mutool/examples/draw-device.js b/docs/mutool/examples/draw-device.js
deleted file mode 100644
index 42ec263d..00000000
--- a/docs/mutool/examples/draw-device.js
+++ /dev/null
@@ -1,45 +0,0 @@
-// Use device interface to draw some graphics and save as a PNG.
-
-var font = new Font("Times-Roman");
-var image = new Image("example.png");
-var path, text;
-
-var pixmap = new Pixmap(DeviceRGB, [0,0,500,600], false);
-pixmap.clear(255);
-var device = new DrawDevice(Identity, pixmap);
-var transform = [2,0,0,2,0,0]
-{
- text = new Text();
- {
- text.showString(font, [16,0,0,-16,100,30], "Hello, world!");
- text.showString(font, [0,16,16,0,15,100], "Hello, world!");
- }
- device.fillText(text, transform, DeviceGray, [0], 1);
-
- path = new Path();
- {
- path.moveTo(10, 10);
- path.lineTo(90, 10);
- path.lineTo(90, 90);
- path.lineTo(10, 90);
- path.closePath();
- }
- device.fillPath(path, false, transform, DeviceRGB, [1,0,0], 1);
- device.strokePath(path, {dashes:[5,10], lineWidth:3, lineCap:'Round'}, transform, DeviceRGB, [0,0,0], 1);
-
- path = new Path();
- {
- path.moveTo(100,100);
- path.curveTo(150,100, 200,150, 200,200);
- path.curveTo(200,300, 0,300, 100,100);
- path.closePath();
- }
- device.clipPath(path, true, transform);
- {
- device.fillImage(image, Concat(transform, [300,0,0,300,0,0]), 1);
- }
- device.popClip();
-}
-device.close();
-
-pixmap.saveAsPNG("out.png");
diff --git a/docs/mutool/examples/draw-document.js b/docs/mutool/examples/draw-document.js
deleted file mode 100644
index 1e285ede..00000000
--- a/docs/mutool/examples/draw-document.js
+++ /dev/null
@@ -1,9 +0,0 @@
-// Draw all pages in a document and save them as PNG files.
-
-var doc = new Document(argv[1]);
-var n = doc.countPages();
-for (var i = 0; i < n; ++i) {
- var page = doc.loadPage(i);
- var pixmap = page.toPixmap(Identity, DeviceRGB);
- pixmap.saveAsPNG("out" + (i+1) + ".png");
-}
diff --git a/docs/mutool/examples/pdf-create-lowlevel.js b/docs/mutool/examples/pdf-create-lowlevel.js
deleted file mode 100644
index 658adfb5..00000000
--- a/docs/mutool/examples/pdf-create-lowlevel.js
+++ /dev/null
@@ -1,63 +0,0 @@
-// Create a PDF from scratch.
-
-// This example creates a new PDF file from scratch, using only the low level APIs.
-// This assumes a basic working knowledge of the PDF file format.
-
-// Create a new empty document with no pages.
-var pdf = new PDFDocument()
-
-// Create and add a font resource.
-var font = pdf.addObject({
- Type: "Font",
- Subtype: "Type1",
- Encoding: "WinAnsiEncoding",
- BaseFont: "Times-Roman",
-})
-
-// Create and add an image resource:
-// Allocate a slot for a new object and get a reference to it.
-var image = pdf.createObject()
-// Write a dictionary object into the slot.
-image.writeObject({
- Type: "XObject",
- Subtype: "Image",
- Width: 4,
- Height: 2,
- BitsPerComponent: 8,
- ColorSpace: "DeviceGray",
- // The compression filter to be used:
- Filter: "ASCIIHexDecode",
-})
-// Write raw stream data into the slot; hex encoded
-// to match the Filter entry in the dictionary.
-image.writeRawStream("004488CCEEBB7733>")
-
-// Create resource dictionary.
-var resources = pdf.addObject({
- Font: { Tm: font },
- XObject: { Im0: image },
-})
-
-// Create content stream.
-var buffer = new Buffer()
-buffer.writeLine("10 10 280 330 re s")
-buffer.writeLine("q 200 0 0 200 50 100 cm /Im0 Do Q")
-buffer.writeLine("BT /Tm 16 Tf 50 50 TD (Hello, world!) Tj ET")
-var contents = pdf.addStream(buffer)
-
-// Create page object.
-var page = pdf.addObject({
- Type: "Page",
- MediaBox: [0,0,300,350],
- Contents: contents,
- Resources: resources,
-})
-
-// Insert page object into page tree.
-var pagetree = pdf.getTrailer().Root.Pages
-pagetree.Count = 1
-pagetree.Kids = [ page ]
-page.Parent = pagetree
-
-// Save the document.
-pdf.save("out.pdf")
diff --git a/docs/mutool/examples/pdf-create.js b/docs/mutool/examples/pdf-create.js
deleted file mode 100644
index 290d1737..00000000
--- a/docs/mutool/examples/pdf-create.js
+++ /dev/null
@@ -1,35 +0,0 @@
-// Create a PDF from scratch using helper functions.
-
-// This example creates a new PDF file from scratch, using helper
-// functions to create resources and page objects.
-// This assumes a basic working knowledge of the PDF file format.
-
-// Create a new empty document with no pages.
-var pdf = new PDFDocument()
-
-// Load built-in font and create WinAnsi encoded simple font resource.
-var font = pdf.addSimpleFont(new Font("Times-Roman"))
-
-// Load PNG file and create image resource.
-var image = pdf.addImage(new Image("example.png"))
-
-// Create resource dictionary.
-var resources = pdf.addObject({
- Font: { Tm: font },
- XObject: { Im0: image },
-})
-
-// Create content stream data.
-var contents =
- "10 10 280 330 re s\n" +
- "q 200 0 0 200 50 100 cm /Im0 Do Q\n" +
- "BT /Tm 16 Tf 50 50 TD (Hello, world!) Tj ET\n"
-
-// Create a new page object.
-var page = pdf.addPage([0,0,300,350], 0, resources, contents)
-
-// Insert page object at the end of the document.
-pdf.insertPage(-1, page)
-
-// Save the document to file.
-pdf.save("out.pdf", "pretty,ascii,compress-images,compress-fonts")
diff --git a/docs/mutool/examples/pdf-merge.js b/docs/mutool/examples/pdf-merge.js
deleted file mode 100644
index d8cdcfcb..00000000
--- a/docs/mutool/examples/pdf-merge.js
+++ /dev/null
@@ -1,67 +0,0 @@
-// A re-implementation of "mutool merge" in JavaScript.
-
-function graftObject(dstDoc, srcDoc, srcObj, map) {
- var srcNum, dstRef, dstObj
- if (!map)
- map = []
- if (srcObj.isIndirect()) {
- srcNum = srcObj.toIndirect()
- if (map[srcNum])
- return map[srcNum]
- map[srcNum] = dstRef = dstDoc.createObject()
- dstRef.writeObject(graftObject(dstDoc, srcDoc, srcObj.resolve(), map))
- if (srcObj.isStream())
- dstRef.writeRawStream(srcObj.readRawStream())
- return dstRef
- }
- if (srcObj.isArray()) {
- dstObj = dstDoc.newArray()
- srcObj.forEach(function (key, val) {
- dstObj[key] = graftObject(dstDoc, srcDoc, val, map)
- })
- return dstObj
- }
- if (srcObj.isDictionary()) {
- dstObj = dstDoc.newDictionary()
- srcObj.forEach(function (key, val) {
- dstObj[key] = graftObject(dstDoc, srcDoc, val, map)
- })
- return dstObj
- }
- return srcObj /* primitive objects are not bound to a document */
-}
-
-function copyPage(dstDoc, srcDoc, pageNumber, map) {
- var srcPage, dstPage
- srcPage = srcDoc.findPage(pageNumber)
- dstPage = dstDoc.newDictionary()
- dstPage.Type = dstDoc.newName("Page")
- if (srcPage.MediaBox) dstPage.MediaBox = graftObject(dstDoc, srcDoc, srcPage.MediaBox, map)
- if (srcPage.Rotate) dstPage.Rotate = graftObject(dstDoc, srcDoc, srcPage.Rotate, map)
- if (srcPage.Resources) dstPage.Resources = graftObject(dstDoc, srcDoc, srcPage.Resources, map)
- if (srcPage.Contents) dstPage.Contents = graftObject(dstDoc, srcDoc, srcPage.Contents, map)
- dstDoc.insertPage(-1, dstDoc.addObject(dstPage))
-}
-
-function copyAllPages(dstDoc, srcDoc) {
- var k, n = srcDoc.countPages()
- var srcMap = []
- for (k = 0; k < n; ++k)
- copyPage(dstDoc, srcDoc, k, srcMap)
-}
-
-function pdfmerge() {
- var srcDoc, dstDoc, i
-
- dstDoc = new PDFDocument()
- for (i = 2; i < argv.length; ++i) {
- srcDoc = new PDFDocument(argv[i])
- copyAllPages(dstDoc, srcDoc)
- }
- dstDoc.save(argv[1], "compress")
-}
-
-if (argv.length < 3)
- print("usage: mutool run pdf-merge.js output.pdf input1.pdf input2.pdf ...")
-else
- pdfmerge()
diff --git a/docs/mutool/examples/trace-device.js b/docs/mutool/examples/trace-device.js
deleted file mode 100644
index 9d7d4373..00000000
--- a/docs/mutool/examples/trace-device.js
+++ /dev/null
@@ -1,102 +0,0 @@
-var Q = JSON.stringify
-
-var pathPrinter = {
- moveTo: function (x,y) { print("moveTo", x, y) },
- lineTo: function (x,y) { print("lineTo", x, y) },
- curveTo: function (x1,y1,x2,y2,x3,y3) { print("curveTo", x1, y1, x2, y2, x3 ,y3) },
- closePath: function () { print("closePath") },
-}
-
-var textPrinter = {
- showGlyph: function (f,m,g,u,v,b) { print("glyph",f,m,g,u,v,b) },
-}
-
-var traceDevice = {
- fillPath: function (path, evenOdd, ctm, colorSpace, color, alpha) {
- print("fillPath", evenOdd, ctm, colorSpace, color, alpha)
- path.walk(pathPrinter)
- },
- clipPath: function (path, evenOdd, ctm) {
- print("clipPath", evenOdd, ctm)
- path.walk(pathPrinter)
- },
- strokePath: function (path, stroke, ctm, colorSpace, color, alpha) {
- print("strokePath", Q(stroke), ctm, colorSpace, color, alpha)
- path.walk(pathPrinter)
- },
- clipStrokePath: function (path, stroke, ctm) {
- print("clipStrokePath", Q(stroke), ctm)
- path.walk(pathPrinter)
- },
-
- fillText: function (text, ctm, colorSpace, color, alpha) {
- print("fillText", ctm, colorSpace, color, alpha)
- text.walk(textPrinter)
- },
- clipText: function (text, ctm) {
- print("clipText", ctm)
- text.walk(textPrinter)
- },
- strokeText: function (text, stroke, ctm, colorSpace, color, alpha) {
- print("strokeText", Q(stroke), ctm, colorSpace, color, alpha)
- text.walk(textPrinter)
- },
- clipStrokeText: function (text, stroke, ctm) {
- print("clipStrokeText", Q(stroke), ctm)
- text.walk(textPrinter)
- },
- ignoreText: function (text, ctm) {
- print("ignoreText", ctm)
- text.walk(textPrinter)
- },
-
- fillShade: function (shade, ctm, alpha) {
- print("fillShade", shade, ctm, alpha)
- },
- fillImage: function (image, ctm, alpha) {
- print("fillImage", image, ctm, alpha)
- },
- fillImageMask: function (image, ctm, colorSpace, color, alpha) {
- print("fillImageMask", image, ctm, colorSpace, color, alpha)
- },
- clipImageMask: function (image, ctm) {
- print("clipImageMask", image, ctm)
- },
-
- beginMask: function (area, luminosity, colorspace, color) {
- print("beginMask", area, luminosity, colorspace, color)
- },
- endMask: function () {
- print("endMask")
- },
-
- popClip: function () {
- print("popClip")
- },
-
- beginGroup: function (area, isolated, knockout, blendmode, alpha) {
- print("beginGroup", area, isolated, knockout, blendmode, alpha)
- },
- endGroup: function () {
- print("endGroup")
- },
- beginTile: function (area, view, xstep, ystep, ctm, id) {
- print("beginTile", area, view, xstep, ystep, ctm, id)
- return 0
- },
- endTile: function () {
- print("endTile")
- },
-
- close: function () {
- print("close")
- },
-}
-
-if (argv.length != 3)
- print("usage: mutool run trace-device.js document.pdf pageNumber")
-else {
- var doc = new Document(argv[1]);
- var page = doc.loadPage(parseInt(argv[2])-1);
- page.run(traceDevice, Identity);
-}