JavaでEPS、PostScript (PS)、XPSドキュメントを結合
Aspose.Page for Javaを使用して、複数のEPS、PostScript (PS)、XPSファイルをプログラムで1つの複数ページPDFドキュメントに結合できます。Adobe Acrobat、Distiller、またはWindowsネイティブの印刷ユーティリティに依存することなく、個々のベクターグラフィックス、印刷ファイル、またはページストリームを異なるドキュメント形式間でシームレスに結合できます。
Aspose.Page for Javaは、専用のレンダリングデバイス (PdfDevice、ImageDevice) と保存オプションを提供し、複数の入力ファイルを変換して統合された1つの出力ストリームに結合できます。
- 分離されたベクターグラフィックスとEPSイラストを統合されたPDFポートフォリオに結合するには、
PsDocument.mergeToPdf()メソッドを使用します。 - 複数ファイルのPostScript印刷ジョブとレポートを1つの印刷可能なPDFファイルに結合するには、
PsDocument.mergeToPdf()メソッドを使用します。 - 異なるXPSファイル、請求書、またはバッチページ出力を1つのXPSまたはPDFパッケージに結合するには、
XpsDocument.merge()メソッドを使用します。
複数のEPSファイルを1つのPDFに結合
個別のEPSベクターグラフィックファイルの配列を1つの複数ページPDFドキュメントに結合します。
import com.aspose.page.eps.PsDocument;
import com.aspose.page.eps.device.PdfSaveOptions;
import com.aspose.page.eps.device.PdfDevice;
import java.io.FileOutputStream;
public class MergeEpsFilesToPdf {
public static void main(String[] args) throws Exception {
// Define array of input EPS files to merge
String[] epsFiles = new String[] {
"C:/Project/Input/graphic1.eps",
"C:/Project/Input/graphic2.eps",
"C:/Project/Input/graphic3.eps"
};
// Initialize output stream for the merged PDF
FileOutputStream outStream = new FileOutputStream("C:/Project/Output/merged_eps_output.pdf");
// SOpen the first EPS document as the base document
PsDocument baseDocument = new PsDocument(epsFiles[0]);
// Configure PDF save options
PdfSaveOptions options = new PdfSaveOptions();
options.setJpegQualityLevel(100);
// Merge additional EPS files and save to PDF stream
baseDocument.mergeToPdf(outStream, epsFiles, options);
outStream.close();
System.out.println("EPS files successfully merged into a single PDF document.");
}
}複数のPostScript (PS) ドキュメントを1つのPDFに結合
カスタムのフォント検索パスとオプションを使用して、複数ページのPostScriptファイルを1つの統合されたPDFストリームに結合します。
import com.aspose.page.eps.PsDocument;
import com.aspose.page.eps.device.PdfSaveOptions;
import java.io.FileOutputStream;
public class MergePsFilesToPdf {
public static void main(String[] args) throws Exception {
// Specify list of PS files
String[] psFiles = new String[] {
"C:/Project/Input/report_part1.ps",
"C:/Project/Input/report_part2.ps"
};
FileOutputStream outStream = new FileOutputStream("C:/Project/Output/merged_report.pdf");
// Load base PS document
PsDocument basePsDoc = new PsDocument(psFiles[0]);
// Set options and configure font folders if custom fonts are used
PdfSaveOptions options = new PdfSaveOptions();
options.setAdditionalFontsFolders(new String[] { "C:/Project/Fonts/" });
// Merge files to PDF
basePsDoc.mergeToPdf(outStream, psFiles, options);
outStream.close();
System.out.println("PostScript documents merged to PDF successfully.");
}
}複数のXPSドキュメントを1つのXPSファイルに結合
異なるXPSパッケージまたは生成された請求書ページを1つの複数ページXPSファイルに結合します。
import com.aspose.page.xps.XpsDocument;
public class MergeXpsFiles {
public static void main(String[] args) throws Exception {
// Open base XPS document
XpsDocument baseDocument = new XpsDocument("C:/Project/Input/document1.xps");
// Define array of additional XPS documents to append
String[] xpsFilesToMerge = new String[] {
"C:/Project/Input/document2.xps",
"C:/Project/Input/document3.xps"
};
// Execute merge operation and save output
baseDocument.merge(xpsFilesToMerge, "C:/Project/Output/merged_document.xps");
baseDocument.close();
System.out.println("XPS documents merged into a single XPS package successfully.");
}
}インストールとセットアップ
Aspose.Page for JavaをMavenに追加します:
Package Manager Console Command
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-page</artifactId>
<version>Latest</version>
</dependency>
FAQ
1. XPS ドキュメントを XPS ではなく PDF に直接結合できますか?
はい。XpsDocument を使用して XPS ドキュメントを読み込み、PdfDevice を使用してセカンダリ ファイルとともにレンダリングすることで、XPS 入力から直接結合された PDF ファイルを作成できます。
2. PS または EPS ファイルを結合する際、Aspose.Page は不足しているフォントをどのように処理しますか?
入力 EPS/PS ファイルでカスタム フォントが参照されている場合は、PdfSaveOptions.setAdditionalFontsFolders() を使用してその場所を指定できます。不足している場合、Aspose.Page は組み込みの既定フォント置換ロジックを使用して、致命的な例外をスローすることなくレンダリングを完了します。
3. 大規模なファイル セットをバッチ処理する際、メモリ効率は維持されますか?
はい。Aspose.Page は PDF デバイスの実行中に入力ページ ストリームを順次処理するため、大規模なエンタープライズ印刷ジョブを低いメモリ オーバーヘッドで効率的に結合できます。