PS Converter for .NET

Introduction to PS Converter for .NET

The PS Converter for .NET is a powerful plugin that allows developers to convert PostScript files to various image formats, including PNG, JPEG, GIF, BMP, and TIFF. This guide provides an overview of the available features and explains how to perform common tasks using code examples in C#.

Converting PostScript Files

To convert a PostScript file, you can use the Process method of the PsConverter class. This method takes two parameters: the input PostScript file path and an instance of PsConverterOptions.

PsConverter converter = new PsConverter();
PsConverterToPdfOptions opt = new PsConverterToPdfOptions();
opt.AddDataSource(new FileDataSource("input.ps"));
opt.AddSaveDataSource(new FileDataSource("output.pdf"));
ResultContainer resultContainer = converter.Process(opt);

You can also specify additional options, such as the page range to convert, the resolution of the output image, and the compression level.

Specifying Conversion Options

To specify conversion options, you can create an instance of the PsConverterOptions class and pass it to the Convert method.

using (var converter = new PsConverter())
{
    var options = new PsConverterToImageOptions();
    options.AddDataSource(new FileDataSource("input.ps"));
    options.AddSaveDataSource(new FileDataSource("output.png"));
    options.Resolution = 300; // set resolution to 300 DPI
    converter.Process(options);
}

Converting PostScript Files to Multiple Image Formats

To convert a PostScript file to multiple image formats, you can use the Convert method with different output file paths.

using (var converter = new PsConverter())
{
    var opt1 = new PsConverterToImageOptions();
    opt1.AddDataSource(new FileDataSource("input.ps"));
    opt1.AddSaveDataSource(new FileDataSource("output.png"));

    converter.Process(opt1);

    var opt2 = new PsConverterToImageOptions();
    opt1.AddDataSource(new FileDataSource("input.ps"));
    opt1.AddSaveDataSource(new FileDataSource("output.jpg"));

    converter.Process(opt2);
}

Handling Errors and Exceptions

The PS Converter for .NET throws exceptions if an error occurs during the conversion process. You can handle these exceptions using try-catch blocks.

try
{
    var options = new PsConverterToImageOptions();
    options.AddDataSource(new FileDataSource("input.ps"));
    options.AddSaveDataSource(new FileDataSource("output.png"));
    converter.Process(options);
}
catch (NotSupportedException ex)
{
    Console.WriteLine($"Error converting file: {ex.Message}");
}

Note that the NotSupportedException class provides additional information about the error, such as the error code and message.

 English