Menambahkan lampiran

Menambahkan lampiran dokumen

  1. Lampirkan PDF sumber ke fasad PdfContentEditor.
  2. Buka file lampiran sebagai aliran masukan.
  3. Panggil addDocumentAttachment(...) dengan stream, nama file, dan deskripsi.
  4. Simpan dokumen PDF yang diperbarui.
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();
    }
}