PS、EPS、XPSの変換

Java用PS、EPS、XPSコンバーターAPIソリューション

 

PostScript PSおよびEncapsulated PostScript EPSファイル、ならびにXPSドキュメントをプログラムで変換する必要がある場合、Java APIはスムーズに複数のファイルを変換できます。PSおよびEPSの場合、APIはレベル1-3のPostScript演算子とほとんどのEPSヘッダーコメントをサポートし、数種類のフォントケースを除いて最大限の適合性を持ってPostScriptドキュメントを変換します。APIは、Times New Romanのようなフォントを処理します。

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

ここでのJava用APIソリューションを使用すると、PS、EPS、XPSなどのPDL形式のファイルをプログラムで変換できますが、これらのネイティブAPIで開発されたクロスプラットフォームツールを見て試してみるのも役立つでしょう。

JavaによるPostScriptからPDFへの変換

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

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

// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(getDataDir() + "input.ps");

// If you want to convert Postscript file despite of minor errors set this flag
boolean 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.setAdditionalFontsFolders(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, java.awt.Dimension(595x842));
// or
//saveOptions.setSize(new java.awt.Dimension(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.setConvertFontsToTTF(false);

// Save document as PDF
document.saveAsPdf(getOutputDir() + "outputPDF_out.pdf", options);

//Review errors
if (suppressErrors) {
    for (Exception ex : options.getExceptions()) {
        System.out.println(ex.getMessage());
    }
}
 

JavaによるPostScriptから画像への変換

EPS/PS PostScriptから画像へのコンバーターアプリケーションの場合、次のJavaコードが有効に機能するため、次の手順を実行します。

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

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

// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(getDataDir() + "inputForImage.ps");

// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;

//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();

//Set output image format.
options.setImageFormat(ImageFormat.PNG);

// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });

// Save PS document to an image.
document.saveAsImage(options, getOutputDir(), getFileNameWithoutExtension(outputFileName));

//Review errors
if (suppressErrors) {
    for (Exception ex : options.getExceptions()) {
        System.out.println(ex.getMessage());
    }
}
 

JavaによるXPSから画像(JPG、PNG、BMP)への変換

Java APIは、ページレイアウトの表現に使用されるXPS形式を処理します。どのようなシナリオにおいても、プログラムでXPSを画像(BMP、JPG、PNG、TIFF)に変換する必要がある場合は、次のコードをJavaアプリケーション内に簡単に統合できます。

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

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

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

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

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



FAQ

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

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

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

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

3. 機能は無料ですか?

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

 

JavaによるXPSからPDFへの変換

プログラムでXPSをPDFドキュメントに変換するプロセスはシンプルで、入力ファイルと出力ファイルの間で忠実度の高い結果が得られます。

  1. XpsDocument クラスを使用して XPS ファイルを読み込みます。
  2. PdfSaveOptions オブジェクトを作成します。
  3. 出力ファイルのパスとオプションオブジェクトを指定して XpsDocument.saveAsPdf() を呼び出します。
XPSからPDFへの変換用Javaコード
// Convert XPS file to PDF document.
// Learn more: https://docs.aspose.com/page/java/convert-xps/

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

// Initialize options object with necessary parameters.
PdfSaveOptions options = new PdfSaveOptions();
options.setJpegQualityLevel(100);
options.setImageCompression(PdfImageCompression.Jpeg);
options.setTextCompression(PdfTextCompression.Flate);
options.setPageNumbers(new int[] { 1, 2, 6 });

// Save document as PDF
document.saveAsPdf(getOutputDir() + "XPStoPDF_out.pdf", options);