How to load the base64 string in PDF Viewer
Load base64 to PDF Viewer
PDF Viewer supports loading the PDF document from the database as a base64 string using the documentPath API.
The following code example will get the PDF document as a byte array using its name from the database and convert the same into a 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;
con.Open();
System.Data.SqlClient.SqlDataReader read = cmd.ExecuteReader();
read.Read();
// Reads the PDF document data as a byte array from the database
byte[] byteArray = (byte[])read["Data"];
// Converts the byte array into a base64 string
return "data:application/pdf;base64," + Convert.ToBase64String(byteArray);
}
Please modify the database name and its entries as per your database entries.
Refer to the sample to load the base64 string in PDF Viewer.
https://www.syncfusion.com/downloads/support/directtrac/general/ze/EJ2PdfViewer_Core-135324210
In the sample, clicking 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.
I hope you enjoyed learning about how to load the base64 string in PDF Viewer.
You can refer to our ASP.NET MVC PDF Viewer feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our ASP.NET MVC PDF Viewer example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!