Skip to main content
Skip table of contents

PDF Portfolios

This example demonstrates the use of the PDF Portfolio feature (sometimes called Portable Collections). A PDF Portfolio can contain multiple files integrated into a single PDF.

Files in a PDF Portfolio can be in a wide range of file types created in different applications. For example, a PDF Portfolio can include text documents, e-mail messages, spreadsheets, CAD drawings, and PowerPoint presentations. Files added to a PDF Portfolio are not converted to PDF, and you can edit or modify them in their native application without removing them from the Portfolio.

PDF Portfolios offer several advantages over merging multiple files into a single PDF. For more information, see Adobe's Overview of PDF Portfolios.



package sandbox.collections;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfFileSpecification;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.collection.PdfCollection;


import sandbox.WrapToTest;

public class PortableCollection {

    public static final String DEST = "results/collections/portable_collection.pdf";
    public static final String DATA = "resources/data/united_states.csv";
    public static final String HELLO = "resources/pdfs/hello.pdf";
    public static final String IMG = "resources/images/berlin2013.jpg";
    public static void main(String[] args) throws IOException,
            DocumentException {
        File file = new File(DEST);
        new PortableCollection().createPdf(DEST);

    public void createPdf(String dest) throws IOException, DocumentException {
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));;
        document.add(new Paragraph("Portable collection"));
        PdfCollection collection = new PdfCollection(PdfCollection.TILE);
        PdfFileSpecification fileSpec = PdfFileSpecification.fileEmbedded(
                writer, DATA, "united_states.csv", null);
        writer.addFileAttachment("united_states.csv", fileSpec);
        fileSpec = PdfFileSpecification.fileEmbedded(
                writer, HELLO, "hello.pdf", null);
        writer.addFileAttachment("hello.pdf", fileSpec);
        fileSpec = PdfFileSpecification.fileEmbedded(
                writer, IMG, "berlin2013.jpg", null);
        writer.addFileAttachment("berlin2013.jpg", fileSpec);
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.