Create PDF Portfolios in Java
Contents
[
Hide
]
A PDF portfolio can bundle multiple files inside a single PDF container while preserving each file in its original format.
Create a PDF portfolio
Use this example when you need to package several files into a PDF portfolio collection.
- Create a new PDF Document and enable its Collection.
- Create FileSpecification objects for each input file and set their descriptions.
- Add the files to the portfolio collection and save the output document.
public static void createPdfPortfolio(Path[] inputFiles, Path outputFile) {
try (Document document = new Document()) {
document.setCollection(new Collection());
FileSpecification excel = new FileSpecification(inputFiles[0].toString());
FileSpecification word = new FileSpecification(inputFiles[1].toString());
FileSpecification image = new FileSpecification(inputFiles[2].toString());
excel.setDescription("Excel File");
word.setDescription("Word File");
image.setDescription("Image File");
document.getCollection().add(excel);
document.getCollection().add(word);
document.getCollection().add(image);
document.save(outputFile.toString());
}
}
Remove files from a PDF portfolio
Use this example when an existing PDF portfolio collection should be cleared.
- Open the source PDF Document.
- Delete the document collection entries.
- Save the cleaned output document.
public static void removeFilesFromPdfPortfolio(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
document.getCollection().delete();
document.save(outputFile.toString());
}
}