Could not export to Pdf

18 posts, 0 answers
  1. Linh Hoang
    Linh Hoang avatar
    22 posts
    Member since:
    Dec 2009

    Posted 15 Jun 2015 Link to this post

    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!

  2. Dimitar
    Admin
    Dimitar avatar
    281 posts

    Posted 15 Jun 2015 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Linh Hoang
    Linh Hoang avatar
    22 posts
    Member since:
    Dec 2009

    Posted 15 Jun 2015 in reply to Dimitar Link to this post

    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. 

  5. Dimitar
    Admin
    Dimitar avatar
    281 posts

    Posted 15 Jun 2015 Link to this post

    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
  6. Linh Hoang
    Linh Hoang avatar
    22 posts
    Member since:
    Dec 2009

    Posted 15 Jun 2015 in reply to Dimitar Link to this post

    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.

  7. Linh Hoang
    Linh Hoang avatar
    22 posts
    Member since:
    Dec 2009

    Posted 15 Jun 2015 in reply to Dimitar Link to this post

    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.

  8. Dimitar
    Admin
    Dimitar avatar
    281 posts

    Posted 16 Jun 2015 Link to this post

    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
  9. Linh Hoang
    Linh Hoang avatar
    22 posts
    Member since:
    Dec 2009

    Posted 16 Jun 2015 in reply to Dimitar Link to this post

    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. 

  10. Dimitar
    Admin
    Dimitar avatar
    281 posts

    Posted 17 Jun 2015 Link to this post

    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
  11. Linh Hoang
    Linh Hoang avatar
    22 posts
    Member since:
    Dec 2009

    Posted 17 Jun 2015 in reply to Dimitar Link to this post

    Thank you for your kind help. 
  12. Linh Hoang
    Linh Hoang avatar
    22 posts
    Member since:
    Dec 2009

    Posted 21 Jun 2015 in reply to Dimitar Link to this post

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

  13. Hristo
    Hristo avatar
    11 posts
    Member since:
    Jan 2013

    Posted 22 Jun 2015 in reply to Linh Hoang Link to this post

    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. 

  14. Linh Hoang
    Linh Hoang avatar
    22 posts
    Member since:
    Dec 2009

    Posted 22 Jun 2015 in reply to Hristo Link to this post

    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?

  15. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 25 Jun 2015 Link to this post

    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
  16. Linh Hoang
    Linh Hoang avatar
    22 posts
    Member since:
    Dec 2009

    Posted 29 Jun 2015 in reply to Hristo Valyavicharski Link to this post

    Hi Hristo,

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

  17. Min-Jie
    Min-Jie avatar
    3 posts
    Member since:
    Jun 2013

    Posted 01 Aug in reply to Hristo Link to this post

    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

  18. Min-Jie
    Min-Jie avatar
    3 posts
    Member since:
    Jun 2013

    Posted 01 Aug in reply to Hristo Link to this post

    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.

  19. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    283 posts

    Posted 04 Aug Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017