PDF portfolio creation

<< Click to Display Table of Contents >>

Navigation:  Gnostice Document Studio .NET > Getting Started > Document Conversion >

PDF portfolio creation

The PDF format supports assembly of multiple files into a portfolio. The attached files stay in their original format and they can be opened, read and edited independently. The Document Converter component allows creation of a PDF portfolio. The steps for this are shown below.

 

1.Open Visual Studio and create a new console application

2.Use either the GUI or the Package Manager Console and install the Gnostice.DocumentStudio.Converter NuGet package.

3.Use the code snippet shown below to create a PDF portfolio

 

    // Create DocumentConverter instance
    DocumentConverter documentConverter = new DocumentConverter();
 
    // List of files to be added to the portfolio
    // The first file will be converted to PDF (if it isn't already PDF) and the rest will be attached as the portfolio
    List inputFiles = new List()
    {
        "1.pdf", "2.docx",
        "3.doc", "4.png",
        "5.bmp", "6.jpeg",
        "7.txt", "8.xps"
    };
 
    // Base file name for output file
    string baseFileName = "Converted";
 
    // Convert to PDF
    string outputFileFormat = "pdf";
 
    // Additional parameters to create PDF Portfolio
    PDFEncoderSettings pdfEncoderSettings = new PDFEncoderSettings()
    {
        PDFPortfolioSettings = new PDFPortfolioSettings()
        {
            PortfolioCreationMode = PortfolioCreationMode.OnlyWhenAttachmentsExist,
            PortfolioLayoutMode = PortfolioLayoutMode.Tile
        }
    };
 
    // Convert list of documents to PDF portfolio
    documentConverter.ConvertToFile(inputFiles, outputFileFormat, Environment.CurrentDirectory, 

        baseFileName, ConversionMode.ConvertFirstFileAndAttachRestAsOriginal, pdfEncoderSettings);

 

4.Run application to see converted output file in application bin directory.

 

The following settings (under PDFEncoderSettings.PDFPortfolioSettings) allow control over the portfolio creation process:

PortfolioCreationMode - This setting controls creation of a PDF portfolio. Note that the ConversionMode setting (explained later) has an interaction with this setting and the final output depends on both the settings. Supported values are:

oOff - Portfolio creation is turned off

oAlways - The output PDF is created as a portfolio regardless of whether there are any attachments to add

oWhenInputIsPortfolio - The output PDF is created as a portfolio only if the input PDF is already a portfolio

oOnlyWhenAttachmentsExist - The output PDF is created as a portfolio only when the resulting PDF contains attachments (originally present or newly added by the conversion)

PortfolioLayoutMode - This setting controls the portfolio layout that is displayed when the PDF is opened for view. Supported values are

oDetails

oTile

oHidden

 

The convert method also takes an enumeration called ConversionMode which controls the portfolio creation process. This parameter is used to specify how the input files are used in the generation of the output files. Supported values of this enum are:

ConvertToSeparateFiles - Each input file is independently converted to one PDF file

ConvertToSingleFile - All input files are combined sequentially to produce a single PDF file

ConvertFirstFileAndAttachRestAsOriginal - The first input file is converted to a PDF file and the rest of the input files are attached as-is to the PDF file

CreateNewFileAndAttachAllAsOriginal - A new blank PDF is created and all input files are attached as-is to the PDF file

 

The output that is produced depends on the settings mentioned above. The following table describes how the settings interact and produce the output.

 

PortfolioCreationMode

 

ConversionMode

Off

Always

WhenInputIsPortfolio

OnlyWhenAttachmentsExist

ConvertToSingleFile

Convert all input files to PDF and merge them to a single PDF

Convert all input files to PDF and merge them to form the covering sheets of a PDF portfolio

If first input file is a PDF portfolio:

Convert rest of the files to PDF, merge contents and append content to cover sheet of first PDF file

Else:

Same behavior as Off setting

Same behavior as Off setting but if the resulting PDF file has attachments then it's created as a portfolio

ConvertToSeparateFiles

Convert each input file to a separate PDF file

Convert each input file to separate PDF files with the contents of the input forming the covering sheets of a PDF portfolio

If first input file is a PDF portfolio:

Convert rest of the files to PDF, merge contents and append content to cover sheet of first PDF file

Else:

Same behavior as Off setting

Same behavior as Off setting but if the resulting PDF files have attachments then they are created as a portfolio

ConvertFirstFileAndAttachRestAsOriginal

Convert first file to regular PDF and attach the rest of the files to the converted PDF in their original format

Convert the first file to PDF using its contents as the covering sheets of a PDF portfolio and attach the rest of the files to the portfolio in their original format

If first input file is a PDF portfolio:

Retain first input file as PDF portfolio and attach the rest of the files to the first PDF file in their original format

Else:

Same behavior as Off setting

Same behavior as Off setting but if the resulting PDF file has attachments then it's created as a portfolio

CreateNewFileAndAttachAllAsOriginal

Create a new blank PDF file and attach all the input files to the PDF in their original format

Create a PDF portfolio with a blank covering sheet and attach all the input files to the portfolio in their original format

If first input file is a PDF portfolio:

Create a PDF portfolio with a blank covering sheet and attach all the input files to the portfolio in their original format

Else:

Same behavior as Off setting

Same behavior as Off setting but if the resulting PDF file has attachments then it's created as a portfolio