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

Use pdf viewer with a document stored in a database

Thread ID:





142423 Feb 2,2019 06:07 PM UTC Nov 27,2019 07:07 AM UTC ASP.NET MVC - EJ 2 5
Tags: PDF Viewer
Guillermo Goberna
Asked On February 2, 2019 06:07 PM UTC

I would like to use the pdf viewer 


But the document is not stored in a folder in the webserver, it is stored in a database, so I need to retrieve the document from the database (not a problem) and load the document in the pdfviewer component.

Could you provide an example? 

Thank you.

I'm using the controller and razor view from your website: 


Ramya Thirugnanam [Syncfusion]
Replied On February 4, 2019 12:22 PM UTC

Hi Guillermo, 
Thanks for contacting Syncfusion support. 
PDF viewer supports to load the PDF document from database as base64 string using the documentPath API.  
The below code example will get the PDF document as byte array using its name from the Database and converts the same into base64 string. 
public object GetDocument() 
            string documentID = "Xyz.pdf"; 
            string constr = System.Configuration.ConfigurationManager.ConnectionStrings["PdfDocument"].ConnectionString; 
            System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(constr); 
            //Searches for the PDF document from the Database 
            var query = "select Data from PdfDocuments where DocumentName = '" + documentID + "'"; 
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(query); 
            cmd.Connection = con; 
            System.Data.SqlClient.SqlDataReader read = cmd.ExecuteReader(); 
            // Reads the PDF document data as byte array from the database 
            byte[] byteArray = (byte[])read["Data"]; 
            //converts byte array into base64 string 
            return "data:application/pdf;base64," + Convert.ToBase64String(byteArray); 
Note: Kindly modify the Database name and their entries as per your database entries. 
We have created the sample to load the base64 string in PDF viewer and shared the same in the following link,  
In the preceding sample, clicking on the ‘Load PDF document as Base64String’ will get PDF document from the local disk as base64 string in GetDocument() and load it in PDF viewer using documentPath. Similarly, you can get the PDF document from database and load it into the PDF Viewer. 
Ramya T 

Guillermo Goberna
Replied On February 6, 2019 06:25 AM UTC

Thank you very much,

I left here also the code in case is useful for anyone else: 

<div style="height:800px;width:100%;">

        public ActionResult Visor(int id)
            // Reads the PDF document data as byte array from the database (DBtm is the dbml class that connects to the Documents database)
            byte[] byteArray = DBtm.Documents.First(x => x.IdDocument == id).Document.ToArray();

            //converts byte array into base64 string
            ViewBag.Documento = "data:application/pdf;base64," + Convert.ToBase64String(byteArray);
            return View();

Ramya Thirugnanam [Syncfusion]
Replied On February 6, 2019 06:43 AM UTC

Hi Guillermo,  
Thanks for your update. 
Ramya T   

Replied On November 26, 2019 11:16 AM UTC


Can you help with loading the pdf from azure blob storage url.


Akshaya Arivoli [Syncfusion]
Replied On November 27, 2019 07:07 AM UTC

Hi ,
Thank you for contacting Syncfusion support. 

We can load the PDF document’s blob URL in PDF Viewer, by converting the URL to base64 string using the client-side load() API in the sample level. Please find the below link for reference, 

Please try this and revert us if you have any concerns on this. 



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