Aspose.Page for Python via .NET is an on premise Python API that allows you to add XPS manipulation features to your own applications. The API also supports to convert XPS, EPS & PS documents to other formats.
Directory | Description |
---|---|
Demos | Source code for live demos hosted at https://products.aspose.app/page/family. |
Examples | A collection of Python examples that help you learn the product features. |
- Creation & edition of documents via API.
- Manipulation with pages.
- Manipulation with graphics objects and graphics states.
- Support for various types of painting and colorspaces.
- Manipulation with print tickets in XPS documents.
- Support for cross-package operations in XPS document.
- Convert XPS, PS & EPS documents to other popular formats.
- Merge documents to PDF.
- Resize and crop EPS files.
- Convert raster images to EPS files.
- Conversion of XPS, PS & EPS documents to other popular formats.
- Supports PostScript language levels 1-3 with an exception of font types: Type2 (CFF), Type14 (Chameleon), Types 9, 10, 11).
- Supports XPS and OXPS formats in the latest versions.
Fixed Layout: XPS
Fixed Layout: PDF
Images: PNG, JPEG, TIFF, BMP
Metafiles: EMF, WMF\
Aspose.Page for Python can be integrated with 32-bit and 64-bit Python web or console applications fro Windows where Python 3.6 or later is installed. Packages for Linux and MacOS will be released in the nearest future.
Run pip install aspose-page
to fetch the package. If you already have Aspose.Page for Python and want to get the latest version, please run pip install --upgrade aspose-page
.
In the next code snippet, we are creating a PS document from scratch containing the text “Hello from Aspose!”. After installing Aspose.Page for Python in your environment, you can execute below code sample to see how Aspose.Page API works.
Below code snippet follows these steps:
- Instantiate a
PsSaveOptions
object. - Create PostScript file output stream.
- Instantiate a
PsDocument
object. - Create
aspose.pydrawing.Font
usingaspose.page.ExternalFontCache
. - Fill text with solid brush.
- Save the resultant PostScript file.
The following code snippet is a "Hello, World!" program to show main technique of Aspose.Page for Python in PS files:
from aspose.page.eps import *
from aspose.page.eps.device import *
import aspose.pydrawing *
#Create save options
options = PsSaveOptions()
#Create PS document from PostScript file
document = PsDocument(dir + "document.ps", options, false)
#Create aspose.pydrawing.Font
font = aspose.page.ExternalFontCache.create_font_by_family_name("Times New Roman", font_size, aspose.pydrawing.FontStyle.BOLD)
# Add text fragment to new page at point (50, 150)
document.fill_text("Hello from Aspose!", font, 50, 150, aspose.pydrawing.SolidBrush(aspose.pydrawing.Color.blue))
#Close current page
document.close_page()
#Save the document
document.save()
In the next code snippet, we are creating an empty XPS document containing the text ?Hello from Aspose!?.
Below code snippet follows these steps:
- Instantiate a
XpsDocument
object. - Create 'XpsGlyphs
object with using the insatnce of
XpsDocument`. - Set painting for the glyphs object.
- Create
aspose.pydrawing.Font
usingaspose.page.ExternalFontCache
. - Save the resultant XPS document.
The following code snippet is a "Hello, World!" program to show main technique of Aspose.Page for Python in PS files:
from aspose.page.xps import *
import aspose.pydrawing *
#Create new XPS Document
x_docs = XpsDocument()
#Add glyph to the document
glyphs = x_docs.add_glyphs("Arial", 12, aspose.pydrawing.FontStyle.REGULAR, 300, 450, "Hello World!")
#Set painting for glyphs
glyphs.fill = x_docs.create_solid_color_brush(aspose.pydrawing.Color.black)
#Save result
x_docs.save(dir + "output.xps")
Aspose.Page for Python is a PS/EPS and XPS manipulation API that lets you convert any existing EPS file to JPEG or other raster image formats.
Below code snippet follows these steps:
- Initialize
PsDocument
object from EPS file. - Create
ImageSaveOptions
object with JPEGaspose.pydrawing.imaging.ImageFormat
. - Save the document as images bytes.
import os
import aspose
from aspose.page.eps import *
from aspose.page.eps.device import *
import aspose.pydrawing.imaging *
#Create PsDocument from Postscript file
document = PsDocument(data_dir + "input.eps")
#If you want to convert Postscript file despite of minor errors set this flag
suppress_errors = True
#Initialize options object with necessary parameters.
options = ImageSaveOptions(suppress_errors)
#Default image format is PNG and it is not mandatory to set it in ImageDevice
#Default image size is 595x842 and it is not mandatory to set it in ImageDevice
#options = ImageSaveOptions(aspose.pydrawing.imaging.ImageFormat.jpeg, new Size(595x842), suppress_errors)
#Save document to JPEG images bytes arrays. One bytes array for one page of the input file.
imagesBytes = document.save_as_image(options)
Aspose.Page for Python supports the feature to convert XPS documents to PDF format. To accomplish this requirement, the PdfSaveOptions class has been introduced into the aspose.page.xps.presentation.pdf namespace. Instantiate an object of PdfSaveOptions and pass it as a second argument to the XpsDocument.save(..) method.
Below code snippet follows these steps:
- Create a PDF file output stream.
- Create an XPS document input stream.
- Instantiate
XpsDocument
class with the XPS input stream. - Create
PdfSaveOptions
object with needed settings. - Initialize
PdfDevice
with PDF ouputStream - Call the
XpsDocument.save()
method and pass it PdfDevice and PdfSaveOptions objects convert the XPS document to PDF.
from aspose.page.xps import *
from aspose.page.xps.presentation.pdf import *
#Initialize XpsDocument instance with XPS file
document = XpsDocument(data_dir + "input.xps", XpsLoadOptions())
#Initialize options object with necessary parameters.
options = PdfSaveOptions()
options.jpeg_quality_level = 100
options.image_compression = PdfImageCompression.JPEG
options.text_compression = PdfTextCompression.FLATE
options.page_numbers = [ 1, 2, 6 ]
#Save XPS document as PDF file
document.save_as_pdf(data_dir + "XPStoPDF_out.pdf", options)
Merge multiple XPS into single file in Python with Aspose.Page programmatically. XPS files are merged such that the first one is joined at the end of the other document.
Below code snippet follows these steps:
- Create a XPS file output stream.
- Create the first XPS document input stream.
- Instantiate
XpsDocument
class with the XPS input stream. - Call the
XpsDocument.merge()
method and pass it files to merge and the output XPS stream.
from aspose.page.xps import *
#Load XPS document from the firct XPS file
document = XpsDocument(data_dir + "input.xps", XpsLoadOptions())
#Create an array of XPS files that will be merged with the first one
files_to_merge = [ data_dir + "Demo.xps", data_dir + "sample.xps" ]
# Merge XPS files to output XPS document
document.merge(files_to_merge, data_dir + "mergedXPSfiles.xps")
Crop EPS image without using specialized software. EPS file doesn't loss initial content. It just have bounding box changed.
Below code snippet follows these steps:
- Create EPS file input stream.
- Initialize
PsDocument
object. - Create output EPS stream.
- Call
PsDocument.crop_eps()
method and pass it the output stream and new bounding box, defined by for numbers.
from aspose.page.eps import *
#Initialize PsDocument object with EPS file
doc = PsDocument(data_dir + "input.eps")
#If someone whants to know initial bounding box, get initial bounding box of EPS image
#initial_bounding_box = doc.extract_eps_bounding_box()
#Create an output stream for resized EPS
input_eps_stream = open(data_dir + "output_crop.eps", "wb")
#Create new bounding box
#Bounding box is represented by 4 numbers: x0, y0, x, y, where x0 - left margin, y0 - top margin, x - (x0 + width), y - (y0 + height)
new_bounding_box = [ 260, 300, 480, 432 ]
#Crop EPS image and save it to the output stream.
doc.crop_eps(output_eps_stream, new_bounding_box)
Home | Product Page | Docs | Demos | API Reference | Examples | Blog | Search | Free Support | Temporary License