Добавление вложения

Добавление вложения в документ

  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();
    }
}