添付ファイルの追加
Contents
[
Hide
]
ドキュメント添付の追加
- ソース PDF を
PdfContentEditorファサードにバインドしてください。 - 添付ファイルを入力ストリームとして開いてください。
addDocumentAttachment(...)を、ストリーム、ファイル名、および説明を引数として呼び出してください。- 更新された PDF ドキュメントを保存してください。
public static void addAttachment(Path inputFile, Path attachmentFile, Path outputFile) throws Exception {
PdfContentEditor editor = new PdfContentEditor();
try (InputStream attachmentStream = Files.newInputStream(attachmentFile)) {
editor.bindPdf(inputFile.toString());
editor.addDocumentAttachment(attachmentStream, attachmentFile.getFileName().toString(), "Sample attachment.");
editor.save(outputFile.toString());
} finally {
editor.close();
}
}