Category / Section
How to load the PDF documents which is uploaded using UploadBox control to the PDF Viewer control?
1 min read
How to load the PDF documents which is uploaded using UploadBox control to the PDF Viewer control?
We can view the PDF documents in PDF Viewer control which are uploaded to the UploadBox control.
HTML:
<div class="control"> <div class="posupload"> <ej:UploadBox ID="Upload1" SaveUrl="saveFiles.ashx" RemoveUrl="removeFiles.ashx" AllowDragAndDrop="true" DropAreaText ="Drop File Here" ExtensionsAllow=".pdf" MultipleFilesSelection="false" AsyncUpload="true" AutoUpload="false" FileSize="1073741824" ClientSideOnComplete="complete" runat="server"> </ej:UploadBox> </div> </div> <br /> <div class="control"> <div id="PdfViewer"></div> </div>
In the complete() function of “ClientSideOnComplete” event of the UploadBox, we can initialize the PDF viewer to load the uploaded PDF document.
JS:
//Event Function of ClientSideOnComplete of UploadBox control. function complete(event) { var pdfViewerElement = document.getElementById("PdfViewer"); pdfViewerElement.style.height = "600px"; var upoadedFiles = event.files; var uploadedFile = upoadedFiles.rawFile; var reader = new FileReader(); reader.readAsDataURL(uploadedFile); reader.onload = function () { //Initialize PDF Viewer control. $("#PdfViewer").ejPdfViewer({ serviceUrl: "../api/PdfViewer" }); var pdfViewer = $("#PdfViewer").data("ejPdfViewer"); var uploadedFileUrl = this.result; //Load the uploaded PDF document to the PDF Viewer control. pdfViewer.load(uploadedFileUrl); } }
Sample:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/PDFViewer_Web1757837099