New to Telerik UI for ASP.NET MVC? Start a free 30-day trial
Upload PDF File and Load it in PDFViewer
Environment
Product | Telerik UI for ASP.NET MVC Upload and Telerik UI for ASP.NET MVC PDFViewer |
Progress Telerik UI for ASP.NET MVC version | Created with the 2023.2.718 version |
Description
How can I upload a PDF
file by using the Telerik UI for ASP.NET MVC Upload and display the uploaded file into the Telerik UI for ASP.NET MVC PDFViewer?
Solution
- Define an Upload component in asynchronous mode.
- Define a PDFViewer component and hide it with CSS.
- Subscribe to the
Success
event to access the file information when it is uploaded successfully. - Within the handler, get the name of the uploaded
PDF
file from the event data, get a reference to the PDFViewer, and call thefromFile()
to load the file that is uploaded on the server. - Call the jQuery
show()
method to show the hidden PDFViewer.
View_HtmlHelper
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.2/pdf.js"></script>
<script>
window.pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.2/pdf.worker.js';
</script>
@(Html.Kendo().Upload()
.Name("files")
.Multiple(false)
.Async(a => a
.Save("Async_Save", "Home")
.Remove("Async_Remove", "Home")
.AutoUpload(true)
)
.Events(e => e.Success("onSuccess"))
)
<div class="pdf-viewer-container" style="display: none;">
@(Html.Kendo().PDFViewer()
.Name("pdfviewer")
)
</div>
More ASP.NET MVC Upload Resources
See Also
- Client-Side API Reference of the Upload for ASP.NET MVC
- Server-Side API Reference of the Upload for ASP.NET MVC
- Server-Side TagHelper API Reference of the Upload for ASP.NET MVC
- Client-Side API Reference of the PDFViewer for ASP.NET MVC
- Server-Side API Reference of the PDFViewer for ASP.NET MVC
- Server-Side TagHelper API Reference of the PDFViewer for ASP.NET MVC
- Telerik UI for ASP.NET MVC Breaking Changes
- Telerik UI for ASP.NET MVC Knowledge Base