XtremeDocumentStudio (for Java)
Next-generation multi-format document-processing component suite for Java SE/EE developers
Compatibility
Java 1.6 and later

How to create a PDF portfolio in Java SE/EE

Learn to create PDF portfolios using XtremeDocumentStudio (for Java).
By L. Santhanam

Gnostice XtremeDocumentStudio (for Java) is the next-generation multi-format document-processing component suite for J2SE/J2EE developers. It supports viewing, printing, and converting PDF, DOCX, BMP, JPEG, PNG, JPEG2000 and single-page/multi-page TIFF. In addition to that, it also has special PDF support for merging, splitting, encryption, and redaction.

In the latest release (Version 2015 R7), we have introduced the ability to create PDF portfolios. A PDF portfolio has the familiar .PDF extenstion but it is a special PDF container for multiple files, not just PDF. PDF viewer applications such as Adobe Reader will display included PDFs and simple formats such as text or images natively. For files in other formats, Adobe Reader will allow the end-user to double-click and launch the files in their default programs.

Here is some sample code that we used to create a portfolio.


import java.util.ArrayList;

import com.gnostice.core.XDocException;
import com.gnostice.documents.ConverterException;
import com.gnostice.documents.DocumentConverter;
import com.gnostice.documents.FormatNotSupportedException;
import com.gnostice.documents.PageRangeSettings;
import com.gnostice.documents.enums.ConversionMode;
import com.gnostice.documents.pdf.PDFEncoderSettings;
import com.gnostice.documents.pdf.PortfolioCreationMode;
import com.gnostice.documents.pdf.PortfolioLayoutMode;

public class PDFPortfolioCreationDemo {
  static { XDocSetup.activate(); }
  
  public static void main(String[] args) {
    // Create a document converter instance
    DocumentConverter dc = new DocumentConverter();
    
    // Specify input files
    ArrayList oInputPDFsList = new ArrayList();    
    oInputPDFsList.add("intel-adrenaline.pdf");
    oInputPDFsList.add("SampleLetterToYourSenator.docx");
    oInputPDFsList.add("Blue hills.jpg");
    oInputPDFsList.add("hebrew-rtl-test.txt");
    
    // Create PDF encoding settings
    PDFEncoderSettings pes = new PDFEncoderSettings();
    // Automatically show document previews in a side panel 
    // in viewer application such as Adobe Reader 
    pes.getPortfolioSettings().setPortfolioCreationMode(PortfolioCreationMode.ALWAYS);
    pes.getPortfolioSettings().setLayoutMode(PortfolioLayoutMode.TILE);
    
    // Create page range settings
    ArrayList oPageRangeSettingsList = new ArrayList();
    // Include all pages from all input documents
    oPageRangeSettingsList.add(new PageRangeSettings("-"));
    
    try {
      // Create a PDF portfolio  
      dc.convertToFile(
          // documents to be included in portfolio
          oInputPDFsList,     
          // mime type (PDF)
          "application/pdf",  
          // output directory (current directory)
          ".",                 
          // output file prefix
          "PortFolio1",       
          // PDF encoder settings
          pes,                  
          // conversion mode
          ConversionMode.CREATE_NEW_FILE_AND_ATTACH_ALL_AS_ORIGINAL,
          // password (empty)
          "",                 
          // page ranges (all pages from all documents)
          oPageRangeSettingsList);
      
    } catch (FormatNotSupportedException e) {
      e.printStackTrace();
    } catch (ConverterException e) {
      e.printStackTrace();
    } catch (XDocException e) {
      e.printStackTrace();
    }
  }

}

This makes it easy for end-users to distribute multiple files in a single file container. Adobe Reader has several display modes for PDF portfolios. The "Detail" view will show more information about the embedded files.

You can also set the first file in the input list as the cover sheet and have the rest of the documents embedded. For this, you need to use the ConversionMode.CONVERT_FIRST_FILE_AND_ATTACH_REST_AS_ORIGINAL option.


...

ArrayList oInputPDFsList = new ArrayList();
// the cover sheet
oInputPDFsList.add("CoverPage.pdf");  
// the embedded documents
oInputPDFsList.add("intel-adrenaline.pdf");
oInputPDFsList.add("SampleLetterToYourSenator.docx");
oInputPDFsList.add("Blue hills.jpg");
oInputPDFsList.add("hebrew-rtl-test.txt");

...

  dc.convertToFile(
      oInputPDFsList,     
      "application/pdf",  
      ".",                 
      "PortFolio1",       
      pes,             
      // enum value to use for specifying a cover sheet     
      ConversionMode.CONVERT_FIRST_FILE_AND_ATTACH_REST_AS_ORIGINAL,
      "",                 
      oPageRangeSettingsList);

...

---o0O0o---

Our .NET Developer Tools
XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2017 Gnostice Information Technologies Private Limited. All rights reserved.