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 PDF into the PDF Viewer manually?

Thread ID:





144162 Apr 23,2019 06:05 AM UTC Apr 23,2019 09:13 AM UTC ASP.NET MVC - EJ 2 3
Tags: PDF Viewer
Asked On April 23, 2019 06:05 AM UTC

I'm trying to re implement the choose file from file. by creating a button to select the PDF file then it run a function in the PdfViewerController.cs

public ActionResult Upload()
            string filePath = "";

                HttpPostedFileBase file = Request.Files[0]; //Uploaded file
                int fileSize = file.ContentLength;
                string fileName = file.FileName;
                string mimeType = file.ContentType;
                System.IO.Stream fileContent = file.InputStream;

                file.SaveAs(Server.MapPath("~/") + fileName); //File will be saved in application root

                MemoryStream stream = new MemoryStream();
                PdfRenderer pdfviewer = new PdfRenderer();
                object jsonResult = new object();
                jsonResult = pdfviewer.Load(stream);
                return Content(JsonConvert.SerializeObject(jsonResult));

and on the javascript 

function sendSelectedPDFToServer() {
    var formdata = new FormData(); //FormData object
    var fileInput = document.getElementById('fileInput');
    //Iterating through each files selected in fileInput
    for (i = 0; i < fileInput.files.length; i++) {
        //Appending each file to FormData object
        formdata.append(fileInput.files[i].name, fileInput.files[i]);
    //Creating an XMLHttpRequest and sending
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/PdfViewer/Upload');
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            var PDFFile = xhr.responseText
    return false;

how can I open the returned PDF from javascript ?

Ramya Thirugnanam [Syncfusion]
Replied On April 23, 2019 07:00 AM UTC

Hi Ahmad, 
Thanks for contacting Syncfusion support. 
We can pass the PDF document as base64 string to the documentPath property or load() method of PDF viewer control for loading, when the file path is sent dynamically using “Choose from File” button. Please follow the below KB link, 
In the click event function of the “Choose from File” button, we can pass the file path to the server. In the server, we can convert the PDF document into base64 string with the file path. In the above link, we have provided a web action method GetDocument. In this method, we can pass the file name to the server and get the base64 string to the client. This returned base64 string can be used to load in the PDF viewer control. 
Ramya T 

Replied On April 23, 2019 08:10 AM UTC

it's working now.

Ramya Thirugnanam [Syncfusion]
Replied On April 23, 2019 09:13 AM UTC

Hi Ahmad,  
Thanks for your update. 
Ramya T 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

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

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
Live Chat Icon