PS コンバータ .NET
PS Converter for .NET への導入
PS Converter for .NET は、開発者が PNG、JPEG、GIF、BMP、および TIFF を含むさまざまな画像形式に PostScript ファイルを変換することを可能にする強力なプラグインです。
ポストスクリプトファイルの変換
PostScript ファイルを変換するには、 Process
メソッドのThe PsConverter
この方法は2つのパラメーターを必要とします:入力 PostScript ファイルパスと一例の 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);
また、変換するページ範囲、出力画像の解像度、圧縮レベルなど、追加のオプションを指定することができます。
変換オプションの定義
変換オプションを指定するには、例を作成することができます。 PsConverterOptions
レッスンで、それを渡す。 Convert
メソッド
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 ファイルを複数の画像形式に変換する
PostScript ファイルを複数の画像形式に変換するには、 Convert
異なる出力ファイルパスを持つ方法。
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);
}
誤りと例外の処理
PS Converter for .NET では、変換プロセス中にエラーが発生した場合、例外を投げ出します。
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}");
}
注目すべきは、 NotSupportedException
クラスは、エラーコードやメッセージなど、誤りに関する追加の情報を提供します。