Add Attachment
Contents
[
Hide
]
Add a document attachment
- Bind the source PDF to the
PdfContentEditorfacade. - Open the attachment file as an input stream.
- Call
addDocumentAttachment(...)with the stream, file name, and description. - Save the updated PDF document.
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();
}
}