Viewing PDF documents available in the FileExplorer control using PDF viewer control.
You can open a PDF document in the JavaScript PDF viewer control while clicking the PDF document from the FileExplorer control using its Select event. Include the following code snippet in the Select client-side event of the File Explorer control.
function OpenPdf(args) { if (args.nodeType == "File") { //provides the path of the PDF document. var _filename = args.path + args.name[0]; //For PDF files if (_filename.includes(".pdf")) { // hide the Print and Download icon in the PDF Viewer var items = ~ej.PdfViewer.ToolbarItems.PrintTools & ~ej.PdfViewer.ToolbarItems.DownloadTool; //creating new browser window var ws = window.open("", '_blank', "width=800,height=600,location=no,menubar=no,status=no,titilebar=no,resizable=no") //Adding script and CSS files ws.document.write('<!DOCTYPE html><html><head><title>PdfViewer</title><link rel="stylesheet" type="text/css" href="../Content/ej/default-theme/ej.web.all.min.css"><script src="../scripts/jquery-2.1.4.min.js"><\/script><script src="../scripts/ej/ej.web.all.min.js"><\/script><\/head><body>'); //div to render PDF Viewer ws.document.write('<div style="width:100%;min-height:570px"><div id="container"><\/div><\/div>') //Initializes the PDF Viewer ws.document.write("<script>$(function(){ $('#container').ejPdfViewer({ serviceUrl: '../api/PdfViewer', documentPath: '" + _filename + "', toolbarSettings: { toolbarItem:'" + items + "'}})})<\/script>") ws.document.write('<\/body><\/html>'); ws.document.close(); } } }
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample-1039137741
In the above sample, FileExplorer control is provided with PDF documents. When you select a PDF document, it will open in new window using the PDF viewer control.
Note: The document path provided to the FileExplorer and PDF viewer control in the web API controller should be same.
Conclusion
I hope you enjoyed learning about viewing PDF documents available in the FileExplorer control using PDF viewer control.
You can refer to our JavaScript 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 JavaScript 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, Direct-Trac, or feedback portal. We are always happy to assist you!