Introduction

PostScript (PS) and Encapsulated PostScript (EPS) are vector document formats used in print workflows, legacy publishing systems, and graphics pipelines. Aspose.Page FOSS for Python provides PsDocument — a single class that handles both .ps and .eps files — with methods to export them to PDF or raster images directly from Python code.

The library requires no Ghostscript installation, no Adobe runtime, and no native system dependencies. It runs on Windows, Linux, and macOS. Install it with pip and use it immediately in any Python 3.10+ environment.


Loading PS and EPS Files

PsDocument exposes two class methods for loading a document. from_file() reads from a file path; from_bytes() accepts raw bytes from a stream or upload.

from aspose.page.ps.document import PsDocument

# Load from file path
ps = PsDocument.from_file("document.ps")
eps = PsDocument.from_file("illustration.eps")

# Load from bytes (network stream, upload, etc.)
with open("document.ps", "rb") as f:
    data = f.read()
ps_from_bytes = PsDocument.from_bytes(data)

The is_eps property returns True if the document is an EPS file, which is useful when processing a mixed batch of PS and EPS files through the same code path.


Exporting to PDF

Call to_pdf() on a loaded PsDocument to obtain the output as a bytes object. The result is a valid PDF byte stream that can be written to disk, stored in a database, or returned from an HTTP endpoint.

from pathlib import Path
from aspose.page.ps.document import PsDocument

ps = PsDocument.from_file("input.ps")
pdf_bytes = ps.to_pdf()
Path("output.pdf").write_bytes(pdf_bytes)

No options object is required for a default PDF export. The to_pdf() method accepts an optional options parameter for advanced use cases.


Exporting to Raster Images

To render a PS or EPS document to a raster image, pass an ImageSaveOptions instance to to_image(). Set format to "png" or "jpeg" and dpi to control the output resolution. The method returns a bytes object containing the encoded image.

from pathlib import Path
from aspose.page.ps.document import PsDocument
from aspose.page.ps.output import ImageSaveOptions

eps = PsDocument.from_file("illustration.eps")
opts = ImageSaveOptions(format="png", dpi=150)
png_bytes = eps.to_image(opts)
Path("output.png").write_bytes(png_bytes)

For JPEG output, change format="jpeg". The dpi property defaults to 96 when not set.


Reading EPS Metadata

PsDocument exposes a dsc property that returns a DscMetadata instance when DSC comments are present in the file. DscMetadata provides structured access to bounding box coordinates, page size, orientation, title, and creator fields parsed from the EPS header.

from aspose.page.ps.document import PsDocument

eps = PsDocument.from_file("illustration.eps")
dsc = eps.dsc
if dsc is not None:
    print("Title:", dsc.title)
    print("Bounding box:", dsc.bounding_box)
    print("HiRes bounding box:", dsc.hires_bounding_box)

Batch Conversion

Because all conversion methods return bytes and accept file paths or raw bytes as input, batch processing is direct to implement with standard Python loops or concurrent.futures.

from pathlib import Path
from aspose.page.ps.document import PsDocument

input_dir = Path("ps-files")
output_dir = Path("pdf-output")
output_dir.mkdir(exist_ok=True)

for ps_file in input_dir.glob("*.ps"):
    doc = PsDocument.from_file(str(ps_file))
    out_path = output_dir / ps_file.with_suffix(".pdf").name
    out_path.write_bytes(doc.to_pdf())
    print("Converted:", ps_file.name)

The same pattern applies to EPS files by changing the glob pattern to "*.eps".


Getting Started