Java에서 PDF에 첨부 파일 추가
Contents
[
Hide
]
PDF에 파일을 첨부하려면 소스 문서를 로드하고 FileSpecification을 생성하여 포함된 파일 컬렉션에 추가하고 결과를 저장합니다.
PDF 문서에 첨부 파일 추가
외부 파일을 기존 PDF에 포함해야 하는 경우 이 예를 사용하세요.
- 원본 PDF
Document를 여세요. - 포함하려는 파일에 대한
FileSpecification을 만드세요. EmbeddedFiles컬렉션에 파일 사양을 추가하고 업데이트된 문서를 저장하세요.
public static void addAttachments(Path inputFile, Path attachmentPath, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
FileSpecification fileSpecification = new FileSpecification(attachmentPath.toString(), "Sample text file");
document.getEmbeddedFiles().add(attachmentPath.getFileName().toString(), fileSpecification);
document.save(outputFile.toString());
}
}