SelectPdf for .NET - Pdf Portfolio - VB.NET / 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 VB.NET



Imports SelectPdf

Namespace Controllers
    Public Class PdfPortfolioController
        Inherits Controller

        ' GET: /PdfPortfolio/
        Public Function Index() As ActionResult
            Return View()
        End Function

        <HttpPost> _
        Public Function SubmitAction(collection As FormCollection) As ActionResult
            ' the test files
            Dim filePdf As String = Server.MapPath("~/files/doc.pdf")
            Dim fileHtml As String = Server.MapPath("~/files/document.html")
            Dim fileImage As String = Server.MapPath("~/files/logo.png")

            ' instantiate the pdf portfolio manager
            Dim portfolio As New PdfPortfolioManager()

            ' add files to the portfolio
            Dim pdfFilePdf As New PdfPortfolioFile(filePdf)
            pdfFilePdf.Description = "PDF document"
            portfolio.Files.Add(pdfFilePdf)

            Dim pdfFileHtml As New PdfPortfolioFile(fileHtml)
            pdfFileHtml.Description = "HTML document"
            portfolio.Files.Add(pdfFileHtml)

            Dim pdfFileImage As 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
            Dim pdf As Byte() = portfolio.Save()

            ' close pdf document
            portfolio.Close()

            ' return resulted pdf document
            Dim fileResult As FileResult = New FileContentResult(pdf, "application/pdf")
            fileResult.FileDownloadName = "Document.pdf"
            Return fileResult
        End Function
    End Class
End Namespace