Pdf Portfolios |
A PDF Portfolio contains multiple files assembled into an integrated PDF unit. The 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. The original files retain their individual identities but are assembled into one PDF Portfolio file. You can open, read, edit, and format each component file independently of the other component files in the PDF Portfolio.
PDF portfolios can be handled in .NET applications using SelectPdf with PdfPortfolioManager object. Using PdfPortfolioManager the following tasks can be performed:
Create new PDF portfolio from scratch. Use PdfPortfolioManager.
Manage existing PDF portfolios. Use PdfPortfolioManager and then Load(String) to load the existing file.
Transform an existing PDF document into a PDF portfolio. The old PDF will server as a cover page for the PDF portfolio. Use PdfPortfolioManager and then Load(String) to load the existing file.
Manage embedded files from the PDF portfolio (list files and their properties, add new files, delete existing files). Access files through Files property. For embedded PDF portfolio files, use PdfPortfolioFile objects to manage name, description, creation and modification date or get the file content using Content and ContentAsStream properties and save them as external files.
Manage the PDF portfolio view mode. Use ViewMode property.
Manage the PDF portfolio startup file. Use StartupFileName property.
The following sample code shows how to create a new PDF portfolio, add 3 embedded files, set the view mode and startup file and save the newly created PDF portfolio on disk.
// the test files string filePdf = Server.MapPath("~/files/doc.pdf"); string fileHtml = Server.MapPath("~/files/document.html"); string fileImage = Server.MapPath("~/files/logo.png"); // instantiate the pdf portfolio manager PdfPortfolioManager portfolio = new PdfPortfolioManager(); // add files to the portfolio PdfPortfolioFile pdfFilePdf = new PdfPortfolioFile(filePdf); pdfFilePdf.Description = "PDF document"; portfolio.Files.Add(pdfFilePdf); PdfPortfolioFile pdfFileHtml = new PdfPortfolioFile(fileHtml); pdfFileHtml.Description = "HTML document"; portfolio.Files.Add(pdfFileHtml); PdfPortfolioFile pdfFileImage = new PdfPortfolioFile(fileImage); pdfFileImage.Description = "Image file"; portfolio.Files.Add(pdfFileImage); // set view mode portfolio.ViewMode = PdfPortfolioViewMode.Details; // set startup file portfolio.StartupFileName = "logo.png"; // save pdf document portfolio.Save("Sample.pdf"); // close pdf document portfolio.Close();
The following sample code shows how to go through all embedded files from a PDF portfolio and export all of them to the disk:
// instantiate the pdf portfolio manager PdfPortfolioManager portfolio = new PdfPortfolioManager(); // load existing PDF portfolio file portfolio.Load("portfolio.pdf"); // go though the file list and export all files for (int i = 0; i < portfolio.Files.Count; i++) { PdfPortfolioFile file = portfolio.Files[i]; FileStream s = new FileStream("export\\" + file.Name, FileMode.Create); s.Write(file.Content, 0, file.Content.Length); s.Dispose(); } // close pdf document portfolio.Close();