New to Telerik UI for ASP.NET MVCStart a free 30-day trial

Upload PDF File and Load it in PDFViewer

Environment

ProductTelerik UI for ASP.NET MVC Upload and Telerik UI for ASP.NET MVC PDFViewer
Progress Telerik UI for ASP.NET MVC versionCreated 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

  1. Define an Upload component in asynchronous mode.
  2. Define a PDFViewer component and hide it with CSS.
  3. Subscribe to the Success event to access the file information when it is uploaded successfully.
  4. Within the handler, get the name of the uploaded PDF file from the event data, get a reference to the PDFViewer, and call the fromFile() to load the file that is uploaded on the server.
  5. 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