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