添付ファイルの追加

ドキュメント添付の追加

  1. ソース PDF を PdfContentEditor ファサードにバインドしてください。
  2. 添付ファイルを入力ストリームとして開いてください。
  3. addDocumentAttachment(...) を、ストリーム、ファイル名、および説明を引数として呼び出してください。
  4. 更新された 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();
    }
}