SelectPdf for .NET - Pdf Viewer Preferences - VB.NET / ASP.NET MVC Sample

This sample shows how to create a new PDF document using SelectPdf and set the pdf viewer preferences. With the viewer preferences, users can specify how the pdf document will appear in a pdf viewer when it is opened.

Sample Code VB.NET

Imports SelectPdf

Namespace Controllers
    Public Class PdfViewerPreferencesController
        Inherits Controller

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

        <HttpPost> _
        Public Function SubmitAction(collection As FormCollection) As ActionResult
            ' create a new pdf document
            Dim doc As New PdfDocument()

            ' add a new page
            Dim page As PdfPage = doc.AddPage()

            ' create a new font
            Dim font As PdfFont = doc.AddFont(PdfStandardFont.Helvetica)
            font.Size = 20

            ' add text element
            Dim text As New PdfTextElement(50, 50,
                    "SelectPdf for .NET - Pdf Viewer Preferences Sample", font)

            ' set the pdf viewer preferences
            doc.ViewerPreferences.CenterWindow = True
            doc.ViewerPreferences.DisplayDocTitle = True
            doc.ViewerPreferences.FitWindow = True
            doc.ViewerPreferences.HideMenuBar = True
            doc.ViewerPreferences.HideToolbar = True
            doc.ViewerPreferences.HideWindowUI = False

            doc.ViewerPreferences.NonFullScreenPageMode =
            doc.ViewerPreferences.PageLayout = PdfViewerPageLayout.SinglePage
            doc.ViewerPreferences.PageMode = PdfViewerPageMode.UseNone

            ' save pdf document
            Dim pdf As Byte() = doc.Save()

            ' close pdf document

            ' 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