Convert PS, EPS, and XPS
PS, EPS, and XPS conversion with API Solution for .NET.
Whenever the need to convert PostScript PS and Encapsulated PostScript EPS Files and XPS documents programmatically, .NET API can do it smoothly and converts multiple files. For PS and EPS, API supports Levels 1-3 PostScript operators, and most of the EPS header comments as well as transforms PostScript documents having maximum conformity with the exception of a few font cases, and API deals with such fonts as Time New Roman.
Moreover, for XPS file transformation, API can add or remove pages, deals with canvases, paths, and glyph elements, create vector graphics shapes, and text strings, convert XPS outline items, and more.
The API solution for .NET here lets you convert files of such PDL formats as PS, EPS, and XPS programmatically, but you may find it useful to see and try cross-platform developed on these native APIs.
PostScript to PDF Conversion via C# .NET.
To convert PostScript PS and Encapsulated PostScript EPS files to PDF via .NET API you need to take the next steps:
- Load PS or EPS file using PsDocument Class .
- Set the PDF saving using PdfSaveOptions Class .
- Use FileStream Class for output PDF file.
- PdfDevice Class by initializing with output PDF filestream object.
- Call PsDocument.Save for PDF conversion.
C# Code for PS EPS to PDF Conversion
// The path to the documents directory.
string dataDir = "definedDirectoryPath";
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(dataDir + "input.ps");
// If you want to convert Postscript file despite of minor errors set this flag
bool suppressErrors = true;
//Initialize options object with necessary parameters.
PdfSaveOptions options = new PdfSaveOptions(suppressErrors);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.AdditionalFontsFolders = new string[] { @"{FONT_FOLDER}" };
// Default page size is 595x842 and it is not mandatory to set it in PdfSaveOptions
// But if you need to specify sizeuse following line
//PdfSaveOptions options = new PdfSaveOptions(suppressErrorsnew, Aspose.Page.Drawing.Size(595x842));
// or
//saveOptions.Size = new Aspose.Page.Drawing.Size(595x842);
document.SaveAsPdf(dataDir + "outputPDF_out.pdf", options);
//Review errors
if (suppressErrors)
{
foreach (Exception ex in options.Exceptions)
{
Console.WriteLine(ex.Message);
}
}PostScript to Images Conversion via C# .NET.
For any EPS/PS PostScript to image converter application, the following C# code works well, so take the next steps:
- Load document using PsDocument class having input file stream as a parameter.
- Create ImageSaveOptions Class object and initialize it with the required settings.
- Save each input file page to an image PNG, JPG, TIFF, BMP, etc.
C# Code for PostScript to Images Conversion
// The path to the documents directory.
string dataDir = "definedDirectoryPath";
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(dataDir + "inputForImage.ps");
// If you want to convert Postscript file despite of minor errors set this flag
bool suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.ImageFormat = Aspose.Page.Drawing.Imaging.ImageFormat.Png;
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.AdditionalFontsFolders = new string[] { @"{FONT_FOLDER}" };
// Save PS document as array of image bytes, one bytes array for one page.
byte[][] imagesBytes = document.SaveAsImage(options);
//Save images bytes arrays as image files.
int i = 0;
foreach (byte[] imageBytes in imagesBytes)
{
string imagePath = Path.GetFullPath(dataDir + "out_image" + i.ToString() +"." + options.ImageFormat.ToString().ToLower());
using (FileStream fs = new FileStream(imagePath, FileMode.Create, FileAccess.Write))
{
fs.Write(imageBytes, 0, imageBytes.Length);
}
i++;
}FAQ
1. Can I convert Postscript with this API solution?
Aspose.Page has functionality that allows you to convert PS, XPS, and EPS files to other formats online or programmatically. If you need to transform your files instantly online you may like to use Page Description Language format files Converter cross-platform application.
2. What Page description Languages are supported by the converter?
This conversion functionality supports files with .ps, .eps, and .xps extensions. Such famous PDLs as PDF and SVG are represented as separate solutions in Aspose.products
3. Is the functionality free?
The cross-platform converters are free, when for the API solution you can get a free Trial and then buy the product if needed.
Convert XPS to Images JPG, PNG, BMP via C# .NET.
.NET API also supports XPS Conversion to Images BMP, JPG, PNG, TIFF, etc., and provides XpsDocument Class for XPS operations. To convert XPS to Image take the next steps:
- Load XPS file from the stream.
- Initialize the relevant image save options e.g for XPS to JPG it is JpegSaveOptions and for XPS to PNG its PngSaveOptions . Here is list of all XPS to Image save options .
- Define relevant settings such as SmoothingMode, Resolution, and PageNumbers etc. for rendering. Finally iterate through document partitions to save them into images.
C# Code for XPS to Image Conversion
// The path to the documents directory.
string dataDir = "definedDirectoryPath";
//Outut file
string outputFileName = dataDir + "XPStoImage_out.jpeg";
// Load XPS document form the XPS file
XpsDocument document = new XpsDocument(dataDir + "input.xps", new XpsLoadOptions());
// Initialize options object with necessary parameters.
JpegSaveOptions options = new JpegSaveOptions()
{
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality,
Resolution = 300,
PageNumbers = new int[] { 1, 2, 6 }
};
// Save XPS document to the images byte arrays. The first dimension is for inner documents
/// and the second one is for pages within inner documents.
byte[][][] imagesBytes = document.SaveAsImage(options);
// Iterate through document partitions (fixed documents, in XPS terms)
for (int i = 0; i < imagesBytes.Length; i++)
{
// Iterate through partition pages
for (int j = 0; j < imagesBytes[i].Length; j++)
{
// Initialize image output stream
using (Stream imageStream = System.IO.File.Open(Path.GetDirectoryName(outputFileName) + Path.DirectorySeparatorChar +
Path.GetFileNameWithoutExtension(outputFileName) + "_" + (i + 1) + "_" + (j + 1) +
Path.GetExtension(outputFileName), System.IO.FileMode.Create, System.IO.FileAccess.Write))
// Write image
imageStream.Write(imagesBytes[i][j], 0, imagesBytes[i][j].Length);
}
}Support and Learning Resources
- Learning Resources
- Documentation
- Source Code
- API References
- Product Support
- Free Support
- Paid Support
- Blog
- Release Notes
- Why Aspose.Page for .NET?
- Customers List
- Success Stories