Introducing MuPDF.js 1.0
Jamie Lemon·November 13, 2024

This week sees the latest release of MuPDF.js 1.0 !
We’ve been working hard on improving the API to make the developer experience of working with PDFs more convenient, more productive and easier to use. 1.0 introduces a new wrapper class to make this possible (note: this sits on top of the current “core” class so you can still access all the existing base methods as well).
Here are the featured updates for PDF documents and pages:
Document specific methods
The new PDFDocument class offers the following featured convenience methods:
Create a blank document
Use the static method createBlankDocument to quickly create a new single page PDF document at your required page size (defaults to A4)
Copy a page
Choose a document page to copy from and to within the same document with copyPage.
Create a new blank page
Create new blank pages and insert them in your document at the page index of your choice with newPage.
Delete pages
Easily delete pages by range or keyword with deletePages.
Set page labels
There is now no need to individually set page labels on a per page basis - now you can set all your document page labels in one call with setPageLabelsArray .
Split
Split documents into new documents by page with ease, just use split along with your required page indexes.
Merge
Need to merge another document into the document you are working with? Try merge and choose the location of where you want the merge to start.
Attach files
You can now easily attach files to your PDF with attachFile.
Page specific methods
New and notable page methods are as follows:
Insert text
If you need to insert text at a given location on the page with a given size, color and font then insertText is your friend!
Insert image
Need to insert an image? Go for insertImage - it’s like inserting text, but for images 🙂
Insert link
Create internal (links within your document) or external (URLs) links with insertLink.
Rotate a page
The convenience method rotate allows you to easily rotate pages by 90 degree increments.
Add annotations and redactions more conveniently
To make things easier to use try the new addAnnotation method. With this you can immediately define the type of annotation you want to use along with the size, placement, contents and author. Similarly, with addRedaction you can place redactions faster.
Get page text
If you just need a plain text representation (i.e. no other metadata or markup) of the page text then use getText to extract the content.
Get images
Grab the images on a page with getImages - it returns a handy array of any images along with their metrics.
Investigate page resources
Dig deeper into your page resources with getResourcesXrefObjects - helpful if you really need to start to investigate the PDF objects held within the page.
We hope the new version offers you an improved API, please let us know what you think and get involved on MuPDF.js on Github , try the package out from NPM or ask questions directly on our Discord.
Happy Coding!