Mercurial > hgrepos > Python2 > PyMuPDF
diff mupdf-source/docs/examples/pdf-create.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/pdf-create.js Mon Sep 15 11:43:07 2025 +0200 @@ -0,0 +1,39 @@ +import * as mupdf from "mupdf" + +// 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. + +import mupdf from "mupdf" + +// Create a new empty document with no pages. +var pdf = new mupdf.PDFDocument() + +// Load built-in font and create WinAnsi encoded simple font resource. +var font = pdf.addSimpleFont(new mupdf.Font("Times-Roman")) + +// Load PNG file and create image resource. +var image = pdf.addImage(new mupdf.Image("example.jpg")) + +// 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")
