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

Could not export to Pdf

18 Answers 454 Views
ClientExportManager
This is a migrated thread and some comments may be shown as answers.
Linh Hoang
Top achievements
Rank 1
Linh Hoang asked on 15 Jun 2015, 06:11 AM

Hi everyone,

I've been using Telerik released in Q1 2015. I tried the simplest export to pdf code as follow but it doesn't work once I used Client Export Manager.

My code is just like this:

<div id="foo">Just for testing</div>
<telerik:RadClientExportManager runat="server" ID="RadClientExportManager1">
    <PdfSettings FileName="Myfile.pdf" />
</telerik:RadClientExportManager>
<input type="button" onclick="exportPdf()" value="export" />
<script type="text/javascript">
function exportPdf() {
var exp = $find("<%= RadClientExportManager1.ClientID %>");
exp.exportPDF($telerik.$("#foo"));
}
</script>

When button was clicked, no error had been found but no pdf file was generated. Have I missed anything? Appriciate your help!

18 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 15 Jun 2015, 10:15 AM
Hi,

I have tested the sample provided and it generates a PDF from the respective div. I have tested it with Firefox, Chrome and IE 10 and it works as expected. I am sending you my test page for reference, based on your snippet. You may test if you have something else on your page that may cause the export to fail on your side. If you are not able to resolve the issue, could you specify if it fails in any browser or only in a certain one?

Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Linh Hoang
Top achievements
Rank 1
answered on 15 Jun 2015, 10:26 AM

Hi Dimitar,

Thanks a lot for your reply, I tested on IE 9 and the code did not work. I just tried again on Firefox and yes, pdf file was generated perfectly. 

0
Dimitar
Telerik team
answered on 15 Jun 2015, 01:54 PM
Hi,

IE 9 and Safari browsers require a service to be assigned to the RadClientExportManager PdfSettings ProxyURL, since these browsers do not support File API. You may refer to the IE9 and Safari Compatibility Code Library, which contains a sample implementation of this feature. You may also take a look at the Browser Support help article for further reference.

Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Linh Hoang
Top achievements
Rank 1
answered on 16 Jun 2015, 12:15 AM

Hi Dimitar,

Could you help me to setup export service step by step. I tried to set up your sample project but it did not work. When I clicked export button, it redirected to a blank page: http://localhost:65265/Admin/Manage/Service.svc/Export.

0
Linh Hoang
Top achievements
Rank 1
answered on 16 Jun 2015, 03:31 AM

Hi Dimitar,

I solved the issue. The reason is I placed Service.svc in the wrong place.

I have another question based on your sample project: Can we open exported pdf in a new window?

Thank you very much for your kind support.

0
Dimitar
Telerik team
answered on 16 Jun 2015, 01:49 PM
Hi,

I am afraid that the exported file cannot be opened in a new window.

Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Linh Hoang
Top achievements
Rank 1
answered on 16 Jun 2015, 01:55 PM

Hi Dimitar,

Now I can export single RadHtmlChart to pdf. I wonder if we can export multiple RadHtmlChart (different chart types) to pdf?

Looking foward to your help. Thanks a lot in advance. 

0
Dimitar
Telerik team
answered on 17 Jun 2015, 08:12 AM
Hi,

You could export any HTML elements through the RadClientExportManager. If your charts are inside a wrapper element, you may export that wrapper. You may refer to the RadClientExportManager online demos and documentation for further a broader view how to work with the control.

Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Linh Hoang
Top achievements
Rank 1
answered on 17 Jun 2015, 09:51 AM
Thank you for your kind help. 
0
Linh Hoang
Top achievements
Rank 1
answered on 22 Jun 2015, 12:55 AM

Hi Dimitar,

I tried to export a RadAjaxPanel which consists of around 20 RadHtmlChart and the browser crashed (I am using IE 9). I had a look at this link http://docs.telerik.com/devtools/aspnet-ajax/controls/clientexportmanager/troubleshooting/browser-crashing for fixing similar issue but I could not generate the code. Could you please add compression scripts to your sample projects in previous post (Default.zip)?

0
Hristo
Top achievements
Rank 1
answered on 22 Jun 2015, 02:45 PM

Here is one more option without WCF or WebAPI:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PdfExport.aspx.cs" Inherits="PdfExport" %>
 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
</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>
 
        <div id="foo">
            <span>Some text</span>
 
            <telerik:RadClientExportManager runat="server" ID="RadClientExportManager1">
                <PdfSettings FileName="MyFile.pdf" ProxyURL="PdfExport.aspx" />
            </telerik:RadClientExportManager>
 
            <script type="text/javascript">
                function exportElement() {
                    var exp = $find("RadClientExportManager1");
                    exp.exportPDF($telerik.$("html"));
                }
            </script>
        </div>
 
        <input type="button" onclick="exportElement()" value="Export" />
    </form>
</body>
</html>
 

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.IO;
 
public partial class PdfExport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack && Request.Form["fileName"] != null)
        {
            string fileName = Request.Form["fileName"].ToString();
            string contentType = Request.Form["contentType"].ToString();
            byte[] data = Convert.FromBase64String(Request.Form["base64"].ToString());
 
            Export(fileName, contentType, data);
        }
    }
 
    public void Export(string fileName, string contentType, byte[] data)
    {
        Response.ClearContent();
        Response.ContentType = contentType;
        Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
        Response.AddHeader("Content-Length", data.Length.ToString());
        Response.BinaryWrite(data);
        Response.End();
    }
}

I hope this helps. 

0
Linh Hoang
Top achievements
Rank 1
answered on 22 Jun 2015, 11:32 PM

Hi Hiristo,

Thank you very much for your code, this option improved my current scenarios however the crashing issue is still remained when I export the ajax panel consisting of multiple html charts. Could we export multiple html charts to a single pdf file?

0
Hristo Valyavicharski
Telerik team
answered on 25 Jun 2015, 11:52 AM
Yes it is possible. Just put all charts inside the html element you want to export. 

Sample is attached.

Regards,
Hristo Valyavicharski
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Linh Hoang
Top achievements
Rank 1
answered on 29 Jun 2015, 11:02 PM

Hi Hristo,

Thank you so much for your sample. This definitely helps!

0
Min-Jie
Top achievements
Rank 1
answered on 01 Aug 2016, 07:18 PM

Hi Hristo

I tried the code that you posted for one more option without WCF or WebAPI, but did not work for me. I am not sure what I missed. Is it possible that you can upload a complete project? 

Min-Jie

0
Min-Jie
Top achievements
Rank 1
answered on 01 Aug 2016, 07:28 PM

Just a bit more information why it did not work for me.

The Export(fileName, contentType, data); code never got called. When I click on the Export button, the Open/Save file dialog appeared. This approach will not work with IE9 and Safari.

0
Veselin Tsvetanov
Telerik team
answered on 04 Aug 2016, 12:55 PM
Hello Min-Jie,

Attached you will find a simplified version of the discussed scenario. I have tested it on IE 9 (on Windows Vista) and it successfully executed the export functionality.

Regards,
Veselin Tsvetanov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Rahul
Top achievements
Rank 1
answered on 04 Apr 2017, 02:43 PM

Hi Sir,

i am worry about RadClientExportManager (PDF Export) on Iphone Safari Browser,

help me for this i am not able to pdf export on iphon.

i using Service :

 [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class Service
    {
        [OperationContract]
        [WebInvoke(Method = "POST")]
        public Stream Export(Stream input)
        {
            StreamReader sr = new StreamReader(input);
            string s = sr.ReadToEnd();
            sr.Dispose();
            NameValueCollection qs = HttpUtility.ParseQueryString(s);
            string fileName = qs["fileName"];
            string base64 = qs["base64"];
            string contentType = qs["contentType"];

            byte[] data = Convert.FromBase64String(base64);

            MemoryStream stream = new MemoryStream(data);
            WebOperationContext.Current.OutgoingResponse.ContentType = contentType;
            stream.Position = 0;
            return stream;
        }
    }

 

aspx page :

 

        <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>

        <div class="invoice-box">

            <table>

                <tr>

                    <td>

                        <telerik:RadButton runat="server" OnClientClicked="exportPdf" Text="Export PDF" AutoPostBack="false" UseSubmitBehavior="false">
                            <Icon PrimaryIconUrl="~/Images/_download.png" />
                        </telerik:RadButton>
                        <input type="button" onclick="exportPdf()" value="export" />
                        <telerik:RadClientExportManager runat="server" ID="RadClientExportManager1" ProxyURL="~/Service.svc/Export">
                            <PdfSettings FileName="InvoicedCasesInvoice.pdf" />
                        </telerik:RadClientExportManager>

                    </td>

                    <td>

                        <asp:ImageButton ID="btnPrint" ToolTip="Print" ImageUrl="~/Images/_print.png" runat="server" Style="margin-top: 3px; margin-left: 15px;" OnClientClick="return PrintPanel();" />

                    </td>

                </tr>

            </table>

        </div>

        <asp:Panel ID="pnlContents" CssClass="MyGridView2" runat="server">

            <link href="../assets/invoiceCSS/bootstrap.min.css" rel="stylesheet" />
            <link href="../assets/font-awesome-4.0.3/css/font-awesome.min.css" rel="stylesheet" />
            <link href="../assets/invoiceCSS/invoice.css" rel="stylesheet" />

            <div class="invoice-box">
                <div class="heading">Invoice</div>
                <hr>
                <div class="row">
                    <div class="col-sm-12">
                        <div class="invoice-date">
                            <div class="iverson_logo">
                                <img src="../Images/logo.png" alt="">
                            </div>
                            <p>
                                INVOICE DATE :
                                <asp:Label ID="lblInvoiceDate" Text="" Style="color: #555;" runat="server"></asp:Label>
                            </p>
                            <p>
                                CASE NUMBER : <strong>
                                    <asp:Label ID="lblCaseNumber" Text="caseNumber" Style="color: #555;" runat="server"></asp:Label></strong>
                            </p>

                        </div>
                    </div>
                </div>
                <div class="row mag20">
                    <div class="col-sm-12">
                        <div class="invoice-date">
                            <p>
                                <span>
                                    <asp:Label Text="lblDrName1" ID="lblDrName1" runat="server"></asp:Label></span>
                            </p>
                            <p>
                                <asp:Label Text="lblStreet1" ID="lblStreet1" runat="server" Style="color: #555;"></asp:Label>
                            </p>
                            <p>
                                <asp:Label Text="lblcitystateZip1" ID="lblcitystateZip1" runat="server" Style="color: #555;"></asp:Label>
                            </p>
                        </div>
                    </div>
                </div>
                <br />
                <div class="row">
                    <div class="col-sm-6 mag10">
                        <div class="invoice-date">
                            <p>
                                <span><strong>
                                    <asp:Label ID="drName1" runat="server" Text="drName1"></asp:Label></strong></span>
                            </p>
                        </div>
                    </div>
                    <div class="col-sm-6 mag10">
                        <div class="invoice-date">
                            <p class="align1" style="margin-right: 11px;">
                                <span><strong>
                                    <asp:Label ID="patientName1" runat="server" Text="patientName1"></asp:Label></strong></span>
                            </p>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-sm-12 mag10">
                        <div class="invo-sec">
                            <ul>
                                <li class="inv">
                                    <div class="in-box1 in-box-width1"><strong>QTY</strong></div>
                                    <div class="in-box2 in-box-width2"><strong>PRODUCTS</strong></div>
                                    <div class="in-box2 in-box-width2"><strong>TOOTH</strong></div>
                                    <div class="in-box1 in-box-width1"><strong>AMOUNT</strong></div>
                                </li>

                                <%
                                    if (Pro1 != null)
                                    {
                                        if (Pro1.Count > 0)
                                        {
                                            foreach (var item in Pro1)
                                            {
                                %>
                                <li class="inv">
                                    <div class="in-box-width1"><%= item.Quantity %></div>
                                    <div class="in-box-width2"><%= item.Product %></div>
                                    <div class="in-box-width2"><%= item.Tooth %></div>
                                    <div class="in-box-width1"><%= item.Amount %></div>
                                </li>
                                <% }

                                        }
                                    } %>


                                <li class="inv">
                                    <div class="in-box-width3">
                                        <strong>SUBTOTAL</strong>
                                    </div>
                                    <div class="in-box-width4">
                                        <strong>
                                            <asp:Label ID="lblsubtotal" runat="server" Text="lblsubtotal"></asp:Label></strong>
                                    </div>
                                </li>
                                <li class="inv">
                                    <div class="in-box-width5 in-box3">
                                        <strong class="colo1">TAX</strong>
                                    </div>
                                    <div class="in-box-width6 in-box3">
                                        <strong class="colo1">AMOUNT</strong>
                                    </div>
                                </li>
                                <li class="inv">
                                    <div class="in-box-width7">
                                        TOTAL TAX
                                    </div>
                                    <div class="in-box-width8">
                                        <asp:Label ID="TaxAmount" Text="TaxAmount" runat="server"></asp:Label>
                                    </div>
                                </li>
                                <li class="inv">
                                    <div class="in-box-width7">
                                        DISCOUNT TOTAL
                                    </div>
                                    <div class="in-box-width8">
                                        <asp:Label ID="TotalDiscount" Text="TotalDiscount" runat="server"></asp:Label>
                                    </div>
                                </li>
                                <li class="inv">
                                    <div class="in-box-width7 boder-bottom-0">
                                        <strong class="colo1">INVOICE TOTAL</strong>
                                    </div>
                                    <div class="in-box-width8 boder-bottom-0">
                                        <strong class="colo1">
                                            <asp:Label ID="Totalpayble" runat="server" Text=""></asp:Label></strong>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

            
                </div>

            </div>

        </asp:Panel>


        <script type="text/javascript">
            function exportPdf() {
                var exp = $find("RadClientExportManager1");
                exp.exportPDF($telerik.$("#pnlContents"));
            }
        </script>

 

 

 

 

-----------------------------

please solve this issue i suffring iphone pdf export issue from many days but not able to resolve.

 

 

 

thanks & Regards

Rahul Prasad

 

 


 

 

 

 

 

 

James
Top achievements
Rank 1
commented on 03 Aug 2023, 12:58 AM | edited

I am using a RadClientExportManager to export an ASP word page to a PDF file.  I can create a PDF file with the following code:

<telerik:RadClientExportManager runat="server" ID="RadClientExportManager1">
<PdfSettings filename="Myfile.pdf" />
</telerik:RadClientExportManager>
<input type="button" onclick="exportElement()" value="export" />

<script type="text/javascript">
function exportElement() {
    var exp = $find("<%= RadClientExportManager1.ClientID %>");
     exp.exportPDF($telerik.$("#foo"));

}
</script>
<div id="foo">Lorem ipsum dolor sit amet <telerik:RadTextBox ID="radTextBox1" runat="server" Text='<%# Eval("= RadClientExportManager1.ClientID") %>'></telerik:RadTextBox></div>

The above code seems to work fine.  It renders a button, the Lorem ipsum dolor sit amet Text and radTextBox1 just fine.  I can create a PDF file when I click the button.

The web page is complicated and has a lot of controls and SQL on it.  I have a large part of the page nested in a DIV called form8GreyPanel.  When I change the exportPDF($telerik.$('#foo')) to  exportPdf($telerik.$('#divForm8')) the page renders the web page, the Telerik  button and the textbox, but clicking the button seems to have no effect.  The DIV tag looks like

<div id="divForm8" runat="server" visible="false" class="GreyPanel">

-- some code

</div>

I have tried using other DIV names and table names in the exportPDF($telerik.$('#foo'))  statement, but even though the web page renders, the button does not create any file when clicked.  

I would like to create a file when the button is clicked.

James

Rumen
Telerik team
commented on 07 Aug 2023, 03:19 PM | edited

Hi James,

I tested with the following setup and I was able to export the content of the divForm8 div into a pdf file:

 

        <telerik:RadClientExportManager runat="server" ID="RadClientExportManager1">
            <PdfSettings FileName="Myfile.pdf" />
        </telerik:RadClientExportManager>

        <script type="text/javascript">
            function exportElement() {
                alert("clicked")
                var exp = $find("<%= RadClientExportManager1.ClientID %>");
                exp.exportPDF($telerik.$("#divForm8"));

            }
        </script>
        <telerik:RadScriptBlock ID="SB1" runat="server">
            <div id="divForm8" runat="server" visible="true" class="GreyPanel">Lorem ipsum dolor sit amet
                <telerik:RadTextBox ID="radTextBox1" runat="server" Text='<%# Eval("= RadClientExportManager1.ClientID") %>'></telerik:RadTextBox>aaa
                <input type="button" onclick="exportElement()" value="export" />
            </div>
        </telerik:RadScriptBlock>

 

My advice to troubleshoot the issue on your side is to:

  • look for any JavaScript errors in the DevTools console
  • test in different browsers
  • put an alert in the exportElement function to see whether it is executed
  • make sure that the exported content is well formed
  • start removing the controls and HTML elements inside the div one by one until the export starts to work - this way you will find out exactly which part of the content is causing the problem and can modify it.
Tags
ClientExportManager
Asked by
Linh Hoang
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Linh Hoang
Top achievements
Rank 1
Hristo
Top achievements
Rank 1
Hristo Valyavicharski
Telerik team
Min-Jie
Top achievements
Rank 1
Veselin Tsvetanov
Telerik team
Rahul
Top achievements
Rank 1
Share this question
or