SelectPdf for .NET - Pdf Portfolio - C# / ASP.NET Sample

This sample shows how to use SelectPdf Library for .NET to create a PDF portfolio, add some embedded files to it and set some view settings.

These are the files that will be added to the pdf portfolio:
Test PDF document
Test HTML document
Test image file

Click on the "Create PDF" button below to see the result.


Sample Code C#



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SelectPdf;

namespace SelectPdf.Samples
{
    public partial class pdf_portfolio : System.Web.UI.Page
    {
        protected void BtnCreatePdf_Click(object sender, EventArgs e)
        {
            // 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(Response, false, "Sample.pdf");

            // close pdf document
            portfolio.Close();

        }
    }
}