PS Converter voor .NET

Inleiding tot PS Converter voor .NET

De PS Converter voor .NET is een krachtige plugin die ontwikkelaars in staat stelt PostScript-bestanden te converteren naar verschillende beeldformaat, waaronder PNG, JPEG, GIF, BMP en TIFF. Deze gids biedt een overzicht van de beschikbare functies en verklaart hoe om gemeenschappelijke taken met behulp van code voorbeelden in C# uit te voeren.

PostScript bestanden converteren

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);

U kunt ook aanvullende opties specificeren, zoals het bereik van pagina om te converteren, de resolutie van de output-afbeelding en het compressieniveau.

Het bepalen van conversie-opties

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);
}

PostScript-bestanden om te zetten in meerdere afbeeldingsformaten

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);
}

Verwerking van fouten en uitzonderingen

De PS Converter voor .NET gooien uitzonderingen als er een fout optreedt tijdens het conversieproces.

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.

 Nederlands