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