How to open ASP.NET MVC PDF Viewer in new window?
Essential JS 2 PDF Viewer
The Syncfusion ASP.NET MVC PDF viewer feature tour (Essential JS 2) is a modern enterprise UI toolkit that has been built from the ground up to be lightweight, responsive, modular, and touch-friendly. It is also available in other frameworks such as JavaScript, Angular, and React.
Refer to the following UG link for getting started with the PDF Viewer.
https://ej2.syncfusion.com/aspnetmvc/documentation/pdfviewer/getting-started/
Open PDF Viewer in new window
You can initialize the PDF Viewer in a new window by using window.open(). Refer to the following steps to open the PDF Viewer in a new window:
Step 1:
Create a button and send the AJAX request on the button click to get the PDF document from the server-side using the PDF document name.
<button onclick="LoadPdf();">Load PDF </button>
Step 2:
- Send an AJAX request to the server-side with the PDF document name and return the PDF document data as a base64 string on the success of the AJAX request.
- Initialize the PDF Viewer on the success of the AJAX request by assigning the PDF document’s base64 string to the documentPath API.
public Object GetDocument(jsonObjects jsonObject) { var jsonData = JsonConverter(jsonObject); byte[] docBytes = System.IO.File.ReadAllBytes(GetDocumentPath(jsonData["documentName"])); var docBase64 = "data:application/pdf;base64," + Convert.ToBase64String(docBytes); return (docBase64); }
Step 3:
Refer to the following code to get the PDF document data and return it as a base64 string to the client.
public Object GetDocument(jsonObjects jsonObject) { var jsonData = JsonConverter(jsonObject); byte[] docBytes = System.IO.File.ReadAllBytes(GetDocumentPath(jsonData["documentName"])); var docBase64 = "data:application/pdf;base64," + Convert.ToBase64String(docBytes); return (docBase64); }
In the previously given sample, clicking the ‘Load PDF’ button will send the AJAX request with the PDF document name to the controller, and the PDF document data is returned as a base64 string to the client. On the success of the AJAX request, we have created the PDF Viewer and loaded that base64 string into it.
Conclusion
I hope you enjoyed learning about how to open the ASP.NET MVC PDF Viewer in a new window.
You can refer to our ASP.NET MVC PDF Viewer feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Web Forms 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!