C#/VB.NET: Create a PDF Portfolio

2022-11-30 01:13:00 Written by  support iceblue
Rate this item
(0 votes)

A PDF portfolio is a collection of files that can contain text documents, spreadsheets, emails, images, PowerPoint presentations and drawings. Although a PDF portfolio assembles different types of files into a single unit, each of the files in it retains their original formatting, resolutions and sizes. In this article, you will learn how to programmatically create a PDF portfolio using Spire.PDF for .NET.

Install Spire.PDF for .NET

To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.PDF

Create a PDF Portfolio and Add Files to It

As a PDF portfolio is a collection of files, Spire.PDF for .NET allows you to create it easily using PdfDocument.Collection property. Then you can add files to the PDF portfolio using PdfCollection.AddFile() method. The detailed steps are as follows:

  • Specify the files that need to be added to the PDF portfolio.
  • Create PdfDocument instance.
  • Create a PDF portfolio and add files to it using PdfDocument.Collection.AddFile() method.
  • Save the result file using PdfDocument.SaveToFile() method.
  • C#
  • VB.NET
using System;
using Spire.Pdf;

namespace CreatePDFPortfolio
{
    class Program
    {
        static void Main(string[] args)
        {
            // Specify the files
            String[] files = new String[] { "input.pdf", "sample.docx", "report.xlsx", "Intro.pptx", "logo.png" };

            //Create a PdfDocument instance
            using (PdfDocument pdf = new PdfDocument())
            {
                //Create a PDF portfolio and add files to it
                for (int i = 0; i < files.Length; i++)
                {
                    pdf.Collection.AddFile(files[i]);

                }
                //Save the result file
                pdf.SaveToFile("PortfolioWithFiles.pdf", FileFormat.PDF);
                pdf.Dispose();
            }
        }
    }
}

C#/VB.NET: Create a PDF Portfolio

Create a PDF Portfolio and Add Folders to It

After creating a PDF portfolio, Spire.PDF for .NET also allows you to create folders within the PDF portfolio to further manage the files. The detailed steps are as follows:

  • Specify the files that need to be added to the PDF portfolio.
  • Create PdfDocument instance.
  • Create a PDF Portfolio using PdfDocument.Collection property.
  • Add folders to the PDF portfolio using PdfCollection.Folders.CreateSubfolder() method, and then add files to the folders using PdfFolder.AddFile() method.
  • Save the result file using PdfDocument.SaveToFile() method.
  • C#
  • VB.NET
using System;
using Spire.Pdf;
using Spire.Pdf.Collections;

namespace CreatePDFPortfolio
{
    class Program
    {
        static void Main(string[] args)
        {
            // Specify the files
            String[] files = new String[] { "input.pdf", "sample.docx", "report.xlsx", "Intro.pptx", "logo.png" };

            //Create a PdfDocument instance
            using (PdfDocument pdf = new PdfDocument())
            {
                //Create a PDF portfolio and add folders to it 
                for (int i = 0; i < files.Length; i++)
                {
                    PdfFolder folder = pdf.Collection.Folders.CreateSubfolder("Folder" + i);

                    //Add files to the folders
                    folder.AddFile(files[i]);
                }

                //Save the result file
                pdf.SaveToFile("PortfolioWithFolders.pdf", FileFormat.PDF);
                pdf.Dispose();
            }
        }
    }
}

C#/VB.NET: Create a PDF Portfolio

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Additional Info

  • tutorial_title:
Last modified on Tuesday, 20 June 2023 01:53