Com treballar amb arxius XPS en Python
Com treballar amb arxius XPS en Python
XpsDocument carrega i exporta arxius XML Paper Specification (XPS). Utilització: from_file() Per obrir un document per camí. to_pdf() per exportar com a bytes PDF, o de la seva to_image() amb: ImageSaveOptions per exportar com a PNG o JPEG. Metodes de gestió de pàgines add_page() i de la remove_page() permet modificar l’estructura del document abans de l"exportació.
Carregar un arxiu XPS
from aspose.page.xps.document import XpsDocument
xps = XpsDocument.from_file("input.xps")Exportació a 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())Exportació a 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)))Gestió de pàgines
from aspose.page.xps.document import XpsDocument
xps = XpsDocument.from_file("input.xps")
page = xps.add_page(595, 842)
xps.remove_page(0)