This is a migrated thread and some comments may be shown as answers.

Info on use of PDFVIEWER Server Side

1 Answer 298 Views
PdfViewer
This is a migrated thread and some comments may be shown as answers.
Giuseppe
Top achievements
Rank 1
Giuseppe asked on 21 May 2020, 06:35 PM

Hi, i'm trying your control suite and i started to try the control in subject following the demo ccode of your website and all works fine if i use the default document ( <PdfjsProcessingSettings File="prev.pdf">
        </PdfjsProcessingSettings>). But what should i do if i want to pass the file name in runtime mode dynamically? I tried this:

 

.ASPX FILE

<%@ Page Language="VB" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="PdfProva._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.2/pdf.js"></script>
<script type="text/javascript">
    window.pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.2/pdf.worker.js';
</script>
    <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <script type="text/javascript">
        //Put your JavaScript code here.
    </script>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
    <div>
        <telerik:RadAjaxPanel runat="server">
    <asp:Button ID="Button1" runat="server" Text="Get File Name" OnClick="Button1_Click" />
    <asp:Label ID="Label1" runat="server"></asp:Label>
    <telerik:RadPdfViewer runat="server" ID="RadPdfViewer1" Height="450px" Width="1000px"
        Skin="Default" RenderMode="Lightweight">
        <PdfjsProcessingSettings>
        </PdfjsProcessingSettings>
    </telerik:RadPdfViewer>
</telerik:RadAjaxPanel>
    </div>
        
    </form>
</body>
</html>

 

VB FILE

Imports Telerik.Web.UI

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filename As String = Server.MapPath("~/prev.pdf")
        RadPdfViewer1.PdfjsProcessingSettings.File = filename
        Dim currentPage = RadPdfViewer1.ActivePage
        Dim result As String = String.Format("Opened file with name: <strong>{0}</strong> on page: <strong>{1}</strong><br />", filename, currentPage)
        Label1.Text = result
    End Sub
End Class

The result is that issue an error "PDF file fails to process".

How to solve?

 

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 26 May 2020, 03:09 PM

Hello Giuseppe,

The path to the PDF file should ve virtual, but not physical. Skipping the Server.MapPath part of the provided snippet will allow you to load the desired file successfully:

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim filename As String = "./Test.pdf"
        RadPdfViewer1.PdfjsProcessingSettings.File = filename
        Dim currentPage = RadPdfViewer1.ActivePage
        Dim result As String = String.Format("Opened file with name: <strong>{0}</strong> on page: <strong>{1}</strong><br />", filename, currentPage)
        Label1.Text = result
    End Sub

 

Regards,
Vessy
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
PdfViewer
Asked by
Giuseppe
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Share this question
or