MuPDF.js 1.0.0 released! #119
jamie-lemon
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We've introduced a new, higher level wrapper API which makes common tasks easier.
Featured API updates:
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.
Please try it out, let us know what you think, get involved or ask questions directly on our Discord!
Beta Was this translation helpful? Give feedback.
All reactions