Class PdfMerger
java.lang.Object
cloud.opencode.base.pdf.operation.PdfMerger
PDF Merger
PDF 合并器
Merges multiple PDF documents into one.
将多个 PDF 文档合并为一个。
Features | 主要功能:
- Merge multiple PDF files - 合并多个 PDF 文件
- Merge specific pages - 合并指定页面
- Keep bookmarks and annotations - 保留书签和注释
- Add outline entries - 添加大纲条目
Usage Examples | 使用示例:
// Merge multiple PDFs
PdfMerger.create()
.add(Path.of("doc1.pdf"))
.add(Path.of("doc2.pdf"))
.keepBookmarks(true)
.mergeTo(Path.of("merged.pdf"));
// Merge specific pages
PdfMerger.create()
.addPages(Path.of("document.pdf"), "1-3", "5", "7-10")
.mergeTo(Path.of("selected.pdf"));
Security | 安全性:
- Thread-safe: No — not designed for concurrent use - 线程安全: 否 — 非并发设计
- Null-safe: Yes — parameters are validated - 空值安全: 是 — 参数已验证
- Since:
- JDK 25, opencode-base-pdf V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionadd(PdfDocument document) Adds a PDF document to merge.add(InputStream inputStream) Adds PDF from input stream.Adds a PDF file to merge.Adds multiple PDF files.addOutlines(boolean add) Adds outline entries for each document.Adds specific pages from a PDF.static PdfMergercreate()Creates a new merger.booleanbooleanbooleankeepAnnotations(boolean keep) Keeps annotations from source documents.keepBookmarks(boolean keep) Keeps bookmarks from source documents.merge()Merges and returns document.voidmergeTo(OutputStream outputStream) Merges and writes to stream.voidMerges and saves to file.
-
Method Details
-
add
-
add
Adds a PDF document to merge. 添加要合并的 PDF 文档。- Parameters:
document- PDF document | PDF 文档- Returns:
- this merger | 当前合并器
-
add
Adds PDF from input stream. 从输入流添加 PDF。- Parameters:
inputStream- PDF input stream | PDF 输入流- Returns:
- this merger | 当前合并器
-
addPages
-
addAll
-
keepBookmarks
Keeps bookmarks from source documents. 保留源文档的书签。- Parameters:
keep- whether to keep | 是否保留- Returns:
- this merger | 当前合并器
-
keepAnnotations
Keeps annotations from source documents. 保留源文档的注释。- Parameters:
keep- whether to keep | 是否保留- Returns:
- this merger | 当前合并器
-
addOutlines
Adds outline entries for each document. 为每个文档添加大纲条目。- Parameters:
add- whether to add | 是否添加- Returns:
- this merger | 当前合并器
-
merge
Merges and returns document. 合并并返回文档。- Returns:
- merged document | 合并后的文档
- Throws:
OpenPdfException- if merging fails | 合并失败时抛出异常
-
mergeTo
Merges and saves to file. 合并并保存到文件。- Parameters:
target- target file path | 目标文件路径- Throws:
OpenPdfException- if merging fails | 合并失败时抛出异常
-
mergeTo
Merges and writes to stream. 合并并写入流。- Parameters:
outputStream- target stream | 目标流- Throws:
OpenPdfException- if merging fails | 合并失败时抛出异常
-
getSources
-
isKeepBookmarks
public boolean isKeepBookmarks() -
isKeepAnnotations
public boolean isKeepAnnotations() -
isAddOutlines
public boolean isAddOutlines() -
create
-