How to Create PDF Portfolio
PDF portfolios allow you to bring together content from a variety of sources (for example, PDF, Word, Excel, JPEG files) into one unified container. The original files retain their individual identities but are assembled into a PDF portfolio file. Users can open, read, edit, and format each component file independently of the other component files.
Aspose.PDF for Java allows the creation of PDF Portfolio documents using the Document class. Load the individual file into a FileSpecification object and add them to the Document.Collection object using the add(…) method. Once the files have been added, use the Document class’ save(..) method to generate the portfolio document.
Code Sample
The following example uses a Microsoft XPS File, a Word document, PDF and an image file to create a PDF Portfolio.
A PDF portfolio created with Aspose.PDF
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java | |
//Instantiate Document Object | |
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(); | |
//Instantiate document Collection object | |
doc.setCollection(new com.aspose.pdf.Collection()); | |
//Get Files to add to Portfolio | |
com.aspose.pdf.FileSpecification xps = new com.aspose.pdf.FileSpecification("printoutput.xps"); | |
com.aspose.pdf.FileSpecification word = new com.aspose.pdf.FileSpecification("sample.doc"); | |
com.aspose.pdf.FileSpecification image = new com.aspose.pdf.FileSpecification("aspose.png"); | |
com.aspose.pdf.FileSpecification pdf = new com.aspose.pdf.FileSpecification("363699.PDF"); | |
//Provide description of the files | |
xps.setDescription("XPS File"); | |
word.setDescription("Word File"); | |
image.setDescription("Image File"); | |
pdf.setDescription("PDF File"); | |
//Add files to document collection | |
doc.getCollection().add(xps); | |
doc.getCollection().add(word); | |
doc.getCollection().add(image); | |
doc.getCollection().add(pdf); | |
//Save Portfolio document | |
doc.save("PortFoliio_output.pdf"); |