How to Work with XPS Files in Python

How to Work with XPS Files in Python

How to Work with XPS Files in Python

XpsDocument loads and exports XML Paper Specification (XPS) files. Use from_file() to open a document by path. Call to_pdf() to export as PDF bytes, or to_image() with ImageSaveOptions to export as PNG or JPEG. Page management methods add_page() and remove_page() let you modify the document structure before export.

Load an XPS File

from aspose.page.xps.document import XpsDocument

xps = XpsDocument.from_file("input.xps")

Export to PDF

from pathlib import Path
from aspose.page.xps.document import XpsDocument

xps = XpsDocument.from_file("input.xps")
Path("output.pdf").write_bytes(xps.to_pdf())

Export to PNG

from pathlib import Path
from aspose.page.xps.document import XpsDocument
from aspose.page.ps.output import ImageSaveOptions

xps = XpsDocument.from_file("input.xps")
Path("output.png").write_bytes(xps.to_image(ImageSaveOptions(format="png", dpi=96)))

Page Management

from aspose.page.xps.document import XpsDocument

xps = XpsDocument.from_file("input.xps")
page = xps.add_page(595, 842)
xps.remove_page(0)

See Also