PS、EPS、および XPS の変換

.NET 用 API ソリューションによる PS、EPS、および XPS の変換。

 

PostScript PS および Encapsulated PostScript EPS ファイルや XPS ドキュメントをプログラムで変換する必要がある場合、.NET API を使用すると、複数のファイルをスムーズに変換できます。PS および EPS の場合、API はレベル 1 ~ 3 の PostScript オペレーターとほとんどの EPS ヘッダー コメントをサポートし、いくつかのフォント ケースを除いて最大限の適合性で PostScript ドキュメントを変換します。また、API は Times New Roman などのフォントを処理します。

さらに、XPS ファイルの変換において、API はページの追加または削除、キャンバス、パス、およびグリフ要素の処理、ベクター グラフィックス形状とテキスト文字列の作成、XPS アウトライン項目の変換などを行うことができます。

ここで紹介する .NET 用 API ソリューションを使用すると、PS、EPS、XPS などの PDL 形式のファイルをプログラムで変換できますが、これらのネイティブ API で開発されたクロスプラットフォームを実際に見て試してみるのも有益かもしれません。

C# .NET による PostScript から PDF への変換

.NET API を使用して PostScript PS および Encapsulated PostScript EPS ファイルを PDF に変換するには、次の手順を実行する必要があります。

  1. PsDocument クラスを使用して PS または EPS ファイルを読み込みます。
  2. PdfSaveOptions オブジェクトを作成し、必要な変換オプションを設定します。
  3. 出力ファイルのパスとオプションオブジェクトを指定して PsDocument.SaveAsPdf() を呼び出します。
PS EPS から PDF への変換用 C# コード
// Convert PS file to PDF document.
// Learn more: https://docs.aspose.com/page/net/convert-ps/

// 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);
//If PostScript file contains some graphics written as Type3 font glyphs, but it is not actual glyphs
//the resulting PDF may be incorrect because of default value of options.ConvertFontsToTTF = true
//Try to set this
//options.ConvertFontsToTTF = false;

// Save document as PDF
document.SaveAsPdf(OutputDir + "outputPDF_out.pdf", options);

//Review errors
if (suppressErrors)
{
    foreach (Exception ex in options.Exceptions)
    {
        Console.WriteLine(ex.Message);
    }
}
 

C# .NET による PostScript から画像への変換

あらゆる EPS/PS PostScript から画像へのコンバーター アプリケーションにおいて、次の C# コードが有効です。以下の手順を実行してください。

  1. PsDocument クラスを使用して PS または EPS ファイルを読み込みます。
  2. ImageSaveOptions オブジェクトを作成し、ImageFormat に変換先の形式を設定します。
  3. オプションオブジェクトを指定して PsDocument.SaveAsImage() を呼び出します。
PostScript から画像への変換用 C# コード
// Convert PS file to PNG image.
// Learn more: https://docs.aspose.com/page/net/convert-ps/

//Outut file 
string outputFileName = "output_image.png";

// 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 to an image.
document.SaveAsImage(options, OutputDir, Path.GetFileNameWithoutExtension(outputFileName));

//Review errors
if (suppressErrors)
{
    foreach (Exception ex in options.Exceptions)
    {
        Console.WriteLine(ex.Message);
    }
}



FAQ

1. この API ソリューションで Postscript を変換できますか?

Aspose.Page には、PS、XPS、および EPS ファイルをオンラインまたはプログラムで他の形式に変換できる機能があります。ファイルをオンラインで即座に変換する必要がある場合は、 ページ記述言語形式のファイル コンバーター クロスプラットフォーム アプリケーションを使用できます。

2. コンバーターでサポートされているページ記述言語は何ですか?

この変換機能は、拡張子が .ps、.eps、および .xps のファイルをサポートします。 PDF や SVG などの有名な PDL は、Aspose.products では個別のソリューションとして表されます。

3. 機能は無料ですか?

クロスプラットフォーム コンバーター は無料です。API ソリューションの場合、無料の試用版を取得してから、必要に応じて製品を購入できます。

 

C# .NET による XPS から JPG、PNG、BMP 画像への変換

.NET API は、XPS から BMP、JPG、PNG、TIFF などの画像への変換もサポートしており、XPS 操作用の XpsDocument クラスを提供しています。XPS を画像に変換するには、次の手順を実行します。

  1. XpsDocument クラスを使用して XPS ファイルを読み込みます。
  2. 変換先の形式に対応する保存オプションクラス( PngSaveOptions 、 JpegSaveOptions 、 BmpSaveOptions 、 TiffSaveOptions のいずれか)を作成します。
  3. SmoothingMode、Resolution、PageNumbers などのレンダリングオプションを設定し、オプションオブジェクトを指定して XpsDocument.SaveAsImage() を呼び出します。
XPS から画像への変換用 C# コード
// Convert XPS file to PNG image.
// Learn more: https://docs.aspose.com/page/net/convert-xps/

//Outut file 
string outputFileName = "XPStoPNG_out.png";

// Load XPS document form the XPS file
XpsDocument document = new XpsDocument(DataDir + "input.xps", new XpsLoadOptions());

// Initialize options object with necessary parameters.
PngSaveOptions options = new PngSaveOptions()
{
    SmoothingMode = SmoothingMode.HighQuality,
    Resolution = 300,
    PageNumbers = new int[] { 1, 2, 6 }
};

// Save XPS document to the PNG image files.
document.SaveAsImage(options, OutputDir, outputFileName);