Image Output
Image Output
ImageSaveOptions controls the raster format and resolution when calling to_image() on
PsDocument or XpsDocument. Pass an ImageSaveOptions instance as the options
argument to to_image().
Setting Format and DPI
Create an ImageSaveOptions instance and set format ("png" or "jpeg") and dpi:
from aspose.page.ps.document import PsDocument
from aspose.page.ps.output import ImageSaveOptions
from pathlib import Path
doc = PsDocument.from_file("input.ps")
opts = ImageSaveOptions(format="png", dpi=150)
Path("output.png").write_bytes(doc.to_image(opts))Supported Output Formats
| Format | format value |
|---|---|
| PNG | "png" |
| JPEG | "jpeg" |
Tips and Best Practices
- Use
dpi=150or higher for document preview thumbnails. - Use
dpi=96(the default) for web display or icon generation. - PNG is lossless; use JPEG when file size is more important than quality.
- All
to_image()calls returnbytes— no temporary files required.
API Reference Summary
| Class / Property | Description |
|---|---|
ImageSaveOptions.format | Output format: "png" or "jpeg" |
ImageSaveOptions.dpi | Output resolution in DPI |
ImageSaveOptions.raster_writer | Optional custom raster writer |
ImageSaveOptions.additional_fonts_folder | Optional path to additional fonts |