Welcome Guest Search | Active Topics | Sign In | Register

Charts not loaded in the PDF Options
Greg
Posted: Wednesday, November 13, 2013 11:01:56 AM
Rank: Member
Groups: Member

Joined: 11/13/2013
Posts: 11
Hi,

I am using Telerik charts in my project. I use the EO.Web.ASPXToPDF object to convert my aspx page. When the pdf is created I get a blue image with a question mark instead of my charts. The rest of my web site loads perfectly in PDFs.
All I saw was 3 options
1 - EO.Pdf.HtmlToPdf.Options.MinLoadWaitTime set at 5000 - done.
2 - licence issue with third party compenents: checked that telerik is not an issue. I can have in other PDFs other telerik components such as grids. Also, I still get the question mark image if I try to use a ASP:Chart control instead of Telerik.
3 - make sure I can reach the image by the URL from another page / web browser. My charts are dynamic so if I take the URL and paste it in another page, I get a server error "image not found".

Would you have any suggestion please? Thank you.


Here is more of my code to complete the post:

Code: C#
protected void ibPrintPdf_OnClick(object sender, EventArgs e)
    {
        EO.Pdf.Runtime.AddLicense(...);
        EO.Web.ASPXToPDF _aspxToPDF = new EO.Web.ASPXToPDF();
        _aspxToPDF.PreRender += new EventHandler(AspxToPDF_PreRender);
        phPdfControl.Controls.Add(_aspxToPDF);
        _aspxToPDF.RenderAsPDF();
    }

protected void AspxToPDF_PreRender(object sender, EventArgs e)
    {
        //margins
        EO.Pdf.HtmlToPdf.Options.OutputArea = new System.Drawing.RectangleF(0.1f, 0.1f, 8f, 10.3f);
        //zoom level
        EO.Pdf.HtmlToPdf.Options.ZoomLevel = 1.2F;

        //Hide or show elements to customize the PDF
        ...
    }
eo_support
Posted: Wednesday, November 13, 2013 12:06:25 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

#3 is the problem. ASPXToPDF does the same thing as you do ---- it tries to load the chart Url, not exactly from another window but definitely through a different route. This is because your session is between your client machine and the server, while the image request sent by ASPXToPDF is from your web server (because ASPXToPDF runs on your web server) to your web server. So if for some reason Telerik's Chart control is sensitive about this (or does that on purpose as a security measure), then it will fail.

We do not know exactly how Telerik Chart implements their image handler. So we can not know for sure. As such you may want to consult Telerik about this. The root of the problem is, you have to be able to request the image Url from within your web server as oppose to from your client machine. So for example, if Telerik verifies whether the IP address of the original request is the same as the image request, then you have to turn that off. If Telerik Chart sends a cookie to your client computer, then you have to capture that cookie and pass that cookie to ASPXToPDF too. Telerik should be able to tell you what method they use and how to bypass it. Most Chart control offers the option to generate a physical image file on the server, that usually is the easiest way to bypass these issues. You can optimize your code to only generate physical image files when you call ASPXToPDF.

As a side note, you should declare ASPXToPDF in your page statically instead of creating it dynamically. It needs to load at the early stage of the page's life cycle. Also you can set the options directly before calling RenderAsPDF. There is no need to do that inside PreRender event handler.

Hope this helps. Please let us know if you are able to get it to work.

Thanks!
Greg
Posted: Friday, November 15, 2013 3:06:21 PM
Rank: Member
Groups: Member

Joined: 11/13/2013
Posts: 11
Thank you for your answer. It made me go around my issue by saving my chart as an image in a specific temp folder. I load this image in a hidden div on my page. When people click to save as a pdf I hide my chart and show the image which is the copy of it.

This worked for the asp chart control. I am pretty sure that will work with the telerik charts also.

Thanks again.
eo_support
Posted: Friday, November 15, 2013 4:21:53 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

Yes. That should work. EO.Pdf also provides JavaScript interface for you to detect whether your page is running inside the converter which you may find useful:

http://www.essentialobjects.com/doc/4/htmltopdf/eo_js.aspx

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.