PS、EPS、および XPS を変換する

.NET 用の PS、EPS、および XPS コンバーター API ソリューション。

 

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

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

ここにある .NET の API ソリューションを使用すると、PS、EPS、XPS などの PDL 形式のファイルをプログラムで変換できますが、これらのネイティブ API で開発されたクロスプラットフォームを確認して試すと役立つ場合があります。

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

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

  1. PsDocument クラス を使用して PS または EPS ファイルを読み込みます。
  2. PdfSaveOptions クラス を使用して PDF 保存を設定します。
  3. 出力 PDF ファイルには FileStream Class を使用します。
  4. PdfDevice クラス 出力 PDF ファイルストリーム オブジェクトで初期化することにより。
  5. PsDocument.Save を呼び出して PDF に変換します。
PS EPS から PDF への変換用の C# コード
// 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);
}
}
 

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

EPS/PS PostScript から画像へのコンバーター アプリケーションでは、次の C# コードが適切に機能するため、次の手順を実行します。

  1. 入力ファイル ストリームをパラメーターとして持つ PsDocument クラスを使用してドキュメントを読み込みます。
  2. ImageSaveOptions Class オブジェクトを作成し、必要な設定で初期化します。
  3. 各入力ファイル ページを画像 PNG、JPG、TIFF、BMP などに保存します。
PostScript から画像への変換用の C# コード
// 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. この API ソリューションで Postscript を変換できますか?

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

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

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

3. 機能は無料ですか?

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

 

XPS を C# .NET 経由で画像 JPG、PNG、BMP に変換します。

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

  1. ストリームから XPS ファイルを読み込みます。
  2. 関連する画像保存オプションを初期化します。たとえば、XPS から JPG の場合は JpegSaveOptions です。 XPS から PNG の場合は、その PngSaveOptions 。すべての XPS to Image 保存オプション のリストを次に示します。
  3. SmoothingMode、Resolution、PageNumbers など、レンダリングに関連する設定を定義します。最後に、ドキュメント パーティションを反復処理して、それらを画像に保存します。
XPS から画像への変換用の C# コード
// 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);
}
}