summaryrefslogtreecommitdiff
path: root/docs/mutool/examples/pdf-create.js
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-04-25 15:43:26 +0200
committerTor Andersson <tor.andersson@artifex.com>2016-04-26 15:12:58 +0200
commita7c3d73078f9e0cfc12d7eee86d0e2de197768ab (patch)
tree3c3edc73cf4a49f4e1e8d31e7bc0cd388137314f /docs/mutool/examples/pdf-create.js
parentccba5ca5548a394670f4e71d1df5be0efc66db69 (diff)
downloadmupdf-a7c3d73078f9e0cfc12d7eee86d0e2de197768ab.tar.xz
Add 'mutool run' documentation.
Diffstat (limited to 'docs/mutool/examples/pdf-create.js')
-rw-r--r--docs/mutool/examples/pdf-create.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/docs/mutool/examples/pdf-create.js b/docs/mutool/examples/pdf-create.js
new file mode 100644
index 00000000..38c193a3
--- /dev/null
+++ b/docs/mutool/examples/pdf-create.js
@@ -0,0 +1,35 @@
+// 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")