Working with Portfolio
PDF Portfolios allows the user to bring together content from a variety of sources, including documents, drawings, images, e-mail, spreadsheets and web pages. Essential® PDF allows the user to create portfolios and also to extract the files from them.
Creating a PDF portfolio
You can create a portfolio using PdfPortfolioInformation class and attach a variety of documents using PdfAttachment class. The following code example illustrates this.
using Syncfusion.Pdf;
using Syncfusion.Pdf.Interactive;
//Create a new instance of PdfDocument class
PdfDocument document = new PdfDocument();
//Create a new portfolio
document.PortfolioInformation = new PdfPortfolioInformation();
//Set the view mode of the portfolio
document.PortfolioInformation.ViewMode = PdfPortfolioViewMode.Tile;
//Create the attachment
FileStream pdfStream = new FileStream("CorporateBrochure.pdf", FileMode.Open, FileAccess.Read);
PdfAttachment pdfFile = new PdfAttachment("CorporateBrochure.pdf", pdfStream);
pdfFile.FileName = "CorporateBrochure.pdf";
//Set the startup document to view
document.PortfolioInformation.StartupDocument = pdfFile;
//Add the attachment to the document
document.Attachments.Add(pdfFile);
//Save and close the document.
document.Save("Sample.pdf");
document.Close(true);using Syncfusion.Pdf;
using Syncfusion.Pdf.Interactive;
//Create a new instance of PdfDocument class
PdfDocument document = new PdfDocument();
//Create a new portfolio
document.PortfolioInformation = new PdfPortfolioInformation();
//Set the view mode of the portfolio
document.PortfolioInformation.ViewMode = PdfPortfolioViewMode.Tile;
//Create the attachment
PdfAttachment pdfFile = new PdfAttachment("CorporateBrochure.pdf");
pdfFile.FileName = "CorporateBrochure.pdf";
//Set the startup document to view
document.PortfolioInformation.StartupDocument = pdfFile;
//Add the attachment to the document
document.Attachments.Add(pdfFile);
//Save and close the document.
document.Save("Sample.pdf");
document.Close(true);Imports Syncfusion.Pdf.Interactive
Imports Syncfusion.Pdf.Parsing
'Create a new instance of PdfDocument class
Dim document As New PdfDocument()
'Create a new portfolio
document.PortfolioInformation = New PdfPortfolioInformation()
'Set the view mode of the portfolio
document.PortfolioInformation.ViewMode = PdfPortfolioViewMode.Tile
'Create the attachment
Dim pdfFile As New PdfAttachment("CorporateBrochure.pdf")
pdfFile.FileName = "CorporateBrochure.pdf"
'Set the startup document to view
document.PortfolioInformation.StartupDocument = pdfFile
'Add the attachment to the document
document.Attachments.Add(pdfFile)
'Save and close the document.
document.Save("Sample.pdf")
document.Close(True)You can download a complete working sample from GitHub.
Extracting file from PDF Portfolio
The Essential® PDF provides support for extracting the files from the PDF Portfolio using Attachments property of PdfLoadedDocument class and saving the files to the disk. The following code sample shows the steps to extract files from PDF Portfolio.
using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf.Parsing;
//Load an existing PDF document
PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf");
//Iterate the attachments
foreach (PdfAttachment attachment in document.Attachments)
{
//Extract the attachment and save to the disk
FileStream s = new FileStream(attachment.FileName, FileMode.Create);
s.Write(attachment.Data, 0, attachment.Data.Length);
s.Dispose();
}
//Save and close the document.
document.Save("Sample.pdf");
document.Close(true);using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf.Parsing;
//Load an existing PDF document
PdfLoadedDocument document = new PdfLoadedDocument("Sample.pdf");
//Iterate the attachments
foreach (PdfAttachment attachment in document.Attachments)
{
//Extract the attachment and save to the disk
FileStream s = new FileStream(attachment.FileName, FileMode.Create);
s.Write(attachment.Data, 0, attachment.Data.Length);
s.Dispose();
}
//Save and close the document
document.Save("Output.pdf");
document.Close(true);Imports Syncfusion.Pdf.Interactive
Imports Syncfusion.Pdf.Parsing
'Load the PDF document
Dim document As New PdfLoadedDocument("Sample.pdf")
'Iterate the attachments
For Each attachment As PdfAttachment In document.Attachments
'Extracting the attachment and saving into the local disk
Dim s As New FileStream(attachment.FileName, FileMode.Create)
s.Write(attachment.Data, 0, attachment.Data.Length)
s.Dispose()
Next
'Save and close the document
document.Save("Output.pdf")
document.Close(True)You can download a complete working sample from GitHub.
Removing files from PDF Portfolio
The following code example illustrates how to remove files from an existing PDF portfolio using RemoveAt method or Remove method of PdfAttachmentCollection class.
using Syncfusion.Pdf.Parsing;
//Load the PDF document
PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf");
//Remove the file from the Portfolio
document.Attachments.RemoveAt(0);
//Save and close the document.
document.Save("Sample.pdf");
document.Close(true);using Syncfusion.Pdf.Parsing;
//Load the PDF document
PdfLoadedDocument document = new PdfLoadedDocument("Sample.pdf");
//Remove the file from the Portfolio
document.Attachments.RemoveAt(0);
//Save and close the document
document.Save("Output.pdf");
document.Close();Imports Syncfusion.Pdf.Parsing
'Load the PDF document
Dim document As New PdfLoadedDocument("Sample.pdf")
'Remove the file from the Portfolio
document.Attachments.RemoveAt(1)
'Save and close the document
document.Save("Output.pdf")
document.Close()You can download a complete working sample from GitHub.