SelectPdf for .NET 10 - Pdf Portfolio - C# / .NET 10 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.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using SelectPdf.Universal;

namespace SelectPdf.Samples.Pages
{
    public class PdfPortfolioModel : PageModel
    {
        public void OnGet()
        {

        }

        public IActionResult OnPost()
        {
            // the test files
            string filePdf = Path.Combine(Startup.ServerPath, "wwwroot", "files", "doc.pdf");
            string fileHtml = Path.Combine(Startup.ServerPath, "wwwroot", "files", "document.html");
            string fileImage = Path.Combine(Startup.ServerPath, "wwwroot", "images", "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
            byte[] pdf = portfolio.Save();

            // close pdf document
            portfolio.Close();

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

        }
    }
}