We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to load the PDF file in PDF viewer using VB

Platform: ASP.NET Web Forms |
Control: PdfViewer |
Published Date: September 10, 2018 |
Last Revised Date: June 19, 2019

The PDF document is loaded in the PDF viewer control using the load() method in client-side. The name, path, and base64 string of the PDF document is used to load the document. Refer to the following code.

JavaScript

var pdfviewer=$(“ #pdfviewer”).data(“ejPdfViewer”);
pdfviewer.load(“ HTTP Succinctly”);
 

VB

Imports Newtonsoft.Json
Imports Syncfusion.EJ.PdfViewer
Imports System.IO
Imports System.Web.Http
 
Namespace PdfViewerWeb.WebApi
    Public Class PdfViewerController
        Inherits ApiController
        Public Function Load(ByVal jsonResult As Dictionary(Of String, String)) As Object
            Dim helper As PdfViewerHelper = New PdfViewerHelper()
 
            If jsonResult.ContainsKey("newFileName") Then
                Dim name = jsonResult("newFileName")
                Dim pdfName = name.ToString() & ".pdf"
                helper.Load(HttpContext.Current.Server.MapPath("~/Data/" & pdfName))
            Else
 
                If jsonResult.ContainsKey("isInitialLoading") Then
 
                    If jsonResult.ContainsKey("file") Then
                        Dim name = jsonResult("file")
                        helper.Load(name)
                    Else
                        helper.Load(HttpContext.Current.Server.MapPath("~/Data/HTTP Succinctly.pdf"))
                    End If
                End If
            End If
 
            Return JsonConvert.SerializeObject(helper.ProcessPdf(jsonResult))
        End Function
 
        Public Function FileUpload(ByVal jsonResult As Dictionary(Of String, String)) As Object
            Dim helper As PdfViewerHelper = New PdfViewerHelper()
 
            If jsonResult.ContainsKey("uploadedFile") Then
                Dim fileUrl = jsonResult("uploadedFile")
                Dim byteArray As Byte() = Convert.FromBase64String(fileUrl)
                Dim stream As MemoryStream = New MemoryStream(byteArray)
                helper.Load(stream)
            End If
 
            Return JsonConvert.SerializeObject(helper.ProcessPdf(jsonResult))
        End Function
 
        Public Function Download(ByVal jsonResult As Dictionary(Of String, String)) As Object
            Dim helper As PdfViewerHelper = New PdfViewerHelper()
            Return helper.GetDocumentData(jsonResult)
        End Function
 
        Public Sub Unload()
            Dim helper As PdfViewerHelper = New PdfViewerHelper()
            helper.UnLoad()
        End Sub
    End Class
End Namespace

 

Note:
  • If the name of the PDF document is only passed as a parameter in the load() method, the PDF document must be available in the folder specified in the Load action method in the controller.
  • If the path of the PDF document is passed as a parameter in load() method, the following code should be used in the Load action method in the controller. 
    If jsonResult.ContainsKey("newFileName") Then
                    Dim name = jsonResult("newFileName")                
                    Dim pdfName = name.ToString()
                    helper.Load(pdfName)
     
    

 

You can download the working sample from PdfViewerWeb.Zip.

By executing the program, you will get the output as follows.

Pdf ViewerClicking the Load PDF document button will load the F# Succinctly.pdf document in PDF viewer.

2X faster development

The ultimate ASP.NET Web Forms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile