Javaを使用してEPSファイルをPDFに結合
Aspose.Page EPS Merger の品質をチェックし、無料のオンライン EPS Merger で結果を表示できます。
Aspose.Page for Java EPS Merger を使用すると、Java 仮想マシンが動作するあらゆる OS 上で、Encapsulated PostScript (EPS) ファイルを PDF ドキュメントに結合できます。
EPS ファイルを PDF に結合させるには、いくつかの手順を実行する必要があります。
- 最初の EPS ファイルから PsDocument のインスタンスを作成します。
- 最初のファイルと結合する EPS ファイルの配列を作成します。
- PdfSaveOptions を使用して、AdditionalFontsFolder と SuppressError のブール値を指定します。
- 作成したドキュメントに EPS ファイルを結合し、PDF 保存オプションを使用して PDF として保存します。
- SuppressErrors の値が true(デフォルト)の場合、EPS ファイルを PDF ドキュメントに結合する際に発生したエラーを確認し、Exceptions リストに保存することができます。
次のコードスニペットは、Java で EPS ファイルを PDF ドキュメントに結合する方法を示しています。
1// Merge several EPS files to one PDF document.
2
3// Initialize PS document with the first EPS file
4PsDocument document = new PsDocument(getDataDir() + "input.eps");
5
6// Create an array of PostScript files that will be merged with the first one
7String[] filesForMerge = new String[] { getDataDir() + "input2.eps", getDataDir() + "input3.eps" };
8
9// If you want to convert Postscript file despite of minor errors set this flag
10boolean suppressErrors = true;
11
12//Initialize options object with necessary parameters.
13PdfSaveOptions options = new PdfSaveOptions(suppressErrors);
14// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
15options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
16
17// Default page size is 595x842 and it is not mandatory to set it in SaveOptions
18// But if you need to specify the page size following line
19//PdfSaveOptions options = new PdfSaveOptions(suppressErrors, new java.awt.Dimension(595, 842));
20
21document.mergeToPdf(getOutputDir() + "outputPDF_out.pdf", filesForMerge, options);
22
23//Review errors
24if (suppressErrors) {
25 for (Exception ex : options.getExceptions()) {
26 System.out.println(ex.getMessage());
27 }
28}PdfSaveOptions について考えてみましょう。このクラスを使用すると、EPS ファイルを PDF に結合する際に、さまざまな変換パラメータを指定できます。
- AdditionalFontsFolder は、フォントの場所を指定します。システムフォントフォルダーはデフォルトで常に含まれます。
- SuppressError は、EPS ファイルを PDF に結合する際に、重大ではないエラーが発生した場合の動作を制御します。値が true の場合、結合後に Exceptions フィールドにエラーの一覧を表示できます。デフォルト値は true です。
- Debug は、デバッグ情報をコンソールに出力します。デフォルト値は false です。
EPS Merger で、オンラインで EPS マージを評価できます。
サンプルとデータファイルは GitHub からダウンロードできます。