How To Convert to PDF - pymupdf/PyMuPDF GitHub Wiki
Convert arbitrary documents to PDF
A new feature introduced with PyMuPDF v1.13.3 and extended in v1.13.4, is conversion of arbitrary documents to PDF.
This works using method Document.convertToPDF(from_page=0, to_page=-1, rotation=0)
. The parameters control the input page range and sequence, and page rotation.
If from_page > to_page >= 0
, page sequence is reversed. Default parameters will convert the complete document.
The result is a Python bytes
object. Open it as a new PyMuPDF PDF document, or save it to disk using the ".pdf" file extension.
How well does it work?
- Image files (raster) are fully supported.
- XPS, EPUB, CBZ files work very well, too. Other types like FB2 should also work. See demo script xps-converter.py.
- SVG images do also work (inaccuracies in some cases).
How can you use it?
- You cannot change an XPS with MuPDF. But you can convert it to PDF and then change that.
- See above demo script.
- Batch-convert images to PDF documents.