SelectPdf for .NET - Pdf Portfolio - C# / ASP.NET MVC 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.Web.Mvc;

namespace SelectPdf.Samples.Controllers
    public class PdfPortfolioController : Controller
        // GET: /PdfPortfolio/

        public ActionResult Index()
            return View();

        public ActionResult SubmitAction(FormCollection collection)
            // 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";

            PdfPortfolioFile pdfFileHtml = new PdfPortfolioFile(fileHtml);
            pdfFileHtml.Description = "HTML document";

            PdfPortfolioFile pdfFileImage = new PdfPortfolioFile(fileImage);
            pdfFileImage.Description = "Image file";

            // set view mode
            portfolio.ViewMode = PdfPortfolioViewMode.Details;

            // set startup file
            portfolio.StartupFileName = "logo.png";

            // save pdf document
            byte[] pdf = portfolio.Save();

            // close pdf document
            // return resulted pdf document
            FileResult fileResult = new FileContentResult(pdf, "application/pdf");
            fileResult.FileDownloadName = "Document.pdf";
            return fileResult;