Welcome Guest Search | Active Topics | Sign In | Register

Using ASPXToPDF with Google Charts Options
CPM
Posted: Monday, September 22, 2014 7:07:18 AM
Rank: Member
Groups: Member

Joined: 9/23/2008
Posts: 10
I'm trying to put together a proof of concept for a component that will allow the creation of a PDF from an HTML dashboard that uses Google Charts. When I use your ASPXToPDF control, I get a PDF, but the charts are not rendered. I've used your HTML to PDF tool to successfully create a PDF that has a chart on it, so I'm happy your EO.Pdf component can generate a PDF from the Google javascript content, but I cannot get it working in a web environment.

I've read topics in your support forum related to giving the page sufficient time before rendering, but this has had no impact on the result. I cannot get the manual trigger to work, because the eopdf javascript object is always undefined.

Can you give me an example of how to trigger a conversion manually or advise how best to generate a pdf of a page containing Google charts?

Many thanks.
eo_support
Posted: Monday, September 22, 2014 9:25:10 AM
Rank: Administration
Groups: Administration

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

Google Chart uses SVG and it should work fine with our converter. You can try to increase HtmlToPdf.Options.MinLoadWaitTime and see if it works. Also for the manual trigger, why do you think the eopdf JavaScript is always undefined?

Thanks
CPM
Posted: Monday, September 22, 2014 9:40:31 AM
Rank: Member
Groups: Member

Joined: 9/23/2008
Posts: 10
I have tried increasing the MinLoadWaitTime to 30 secs (The page loads considerably quicker that that, as it is a simple demo with javascript object data sample in the page itself.) and I still get a blank space in the pdf, where the chart should be.

When I try to trigger the conversion manually, I set the HtmlToPdf.Options.TriggerMode = HtmlToPdfTriggerMode.Manual in the Page_Load event and then have a button on the page that calls eopdf.convert(), as suggested in your documentation, but I get the javascript error "Uncaught ReferenceError: eopdf is not defined".
eo_support
Posted: Monday, September 22, 2014 10:51:46 AM
Rank: Administration
Groups: Administration

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

Setting HtmlToPdf.Options.MinLoadWaitTime to 30 seconds should render something. If it does not render anything at all, then the problem is something else. As a test, try to comment RenderAsPDF() call out and see if you get the correct result on screen. If you do not get the correct result on screen, then the problem is somewhere in your own code and you will need to fix that. If you do get correct result on screen, then you can try to isolate the problem into a separate test project and send the test project to us. We will take a look as soon as we receive it. Please see here for test project guideline:

http://www.essentialobjects.com/forum/test_project.aspx

As to the manual trigger, you missed the key point of eopdf.convert(). Object "eopdf" only exists when the page is running inside the converter. When you put a button in your page and click that button with mouse, that page is running inside your own web browser, not inside the converter. So obviously it will be undefined.

Thanks!
CPM
Posted: Monday, September 22, 2014 11:04:30 AM
Rank: Member
Groups: Member

Joined: 9/23/2008
Posts: 10
I will email the project to you.

In the meantime, could you possibly post an sample of how you would trigger the conversion manually?
eo_support
Posted: Monday, September 22, 2014 11:19:59 AM
Rank: Administration
Groups: Administration

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

"Triggering manually" means you can trigger the conversion with code. This is the simplest example on how to use manual trigger:

Code: HTML/ASPX
<body onload="eopdf.convert();">
 .....
</body>


The above code using body.onload event to trigger conversion when the page finishes loading. In your case, you will need to find out some event that will be triggered when your chart finishes loading and trigger the conversion. That will be an event exposed by Google Chart. This is not a user input triggered event since user event such as mouse click not only does not occur in the converter (because it has no UI), but also it has no relationship with whether your Google Chart has been loaded. The whole point of manual trigger is to delay the conversion until certain things have happened --- in your case, it would be that Google Chart has finished loading.

If you load the above code in a regular web browser, you will run into JavaScript error because eopdf is not defined. To avoid such problems, you will need to test whether the page is running inside our converter, for example:

Code: HTML/ASPX
<body onload="if (typeof(eopdf) != 'undefined') eopdf.convert();">
 .....
</body>


Note the if test before calling eopdf.convert(). Once you make this change, the code will run fine both in a regular browser and inside the converter.

The following code would have the same effect as a time based automatic trigger (based on MinLoadWaitTime):

Code: HTML/ASPX
<body onload="setTimeout(function() { if (typeof(eopdf) !='undefined') eopdf.convert(); }, 1000);">
.....
</body>


Since you have already tried to use 30 seconds, most likely it is not a timing issue. In that case most likely your manual trigger will never be called (since the Chart is in fact never loaded). In that case you will get a timeout error.

Hope this clears up.

Thanks

CPM
Posted: Monday, September 22, 2014 11:27:11 AM
Rank: Member
Groups: Member

Joined: 9/23/2008
Posts: 10
Your example above will never trigger the conversion, because eopdf will never be defined. I'm assuming you also need to set the manual trigger in the Page_Load event {HtmlToPdf.Options.TriggerMode = HtmlToPdfTriggerMode.Manual;}, but how does the page ever get a defined eopdf object?
eo_support
Posted: Monday, September 22, 2014 11:34:28 AM
Rank: Administration
Groups: Administration

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

Try to save the above code as a HTML file and then call HtmlToPdf.ConvertUrl to run it through our converter and see what happens. EO.Pdf.dll has it's own embedded browser engine. When you convert a page to PDF, EO.Pdf creates an instance of that browser engine, loads the page into that engine and run all JavaScript code the same way as a regular web browser does. However inside our own browser engine, "eopdf" is always predefined by the browser engine, just like in your browser the object "window" is predefined.

Hope this makes sense to you. If you still do not understand, you will need to ask someone around you to explain this to you. We do not know how to explain it better.

Also the email you sent to us has no attachment.

Thanks!
eo_support
Posted: Monday, September 22, 2014 12:07:50 PM
Rank: Administration
Groups: Administration

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

We have received your test project. We ran it here and it works fine. Our steps are as follow:

1. Open it through File -> Open -> Web Site with Visual Studio 2013;
2. Add reference to the latest EO.Web.dll;
3. Copy the latest EO.Pdf.dll to the bin directory;
4. Run the page. Click "Export As PDF";
5. Wait for 30 seconds (due to you set HtmlToPdf.Options.MinLoadWaitTime to 30 seconds);
6. IE prompt file download. Open the PDF file and we see the three gauges;

We also tested the following steps:
1. Remove HtmlToPdf.Options.MinLoadWaitTime = 3000;
2. Run the page again, we get the correct PDF file immediately;

We used the following steps to test manual trigger:
1. Add HtmlToPdf.Options.TriggerMode = HtmlToPdfTriggerMode.Manual in page load;
2. Remove HtmlToPdf.Options.MinLoadWaitTime = 3000;
3. Add the triggering code inside drawChart after chart.Draw:

Code: JavaScript
if (typeof(eopdf) != "undefined")
   eopdf.convert();


It produced the correct PDF file as well. You can try these steps and see if any step works for you. Our test environment is Windows 7 with IE 11.

Thanks!

MIS Admin
Posted: Friday, July 8, 2016 1:56:55 AM
Rank: Member
Groups: Member

Joined: 7/7/2016
Posts: 24
In my testing, google chart is not showing in correct places. Sometime, it is hiding under other elements. I tried to use converturl(). If I want to download latest eo.pdf.dll, only allow me to download eo.Total. Is it the same? After I added references of dll files, I found an error with EO.Pdf.Internal. How can I solve this problem?
eo_support
Posted: Friday, July 8, 2016 10:48:05 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,275
MIS Admin wrote:
In my testing, google chart is not showing in correct places. Sometime, it is hiding under other elements. I tried to use converturl(). If I want to download latest eo.pdf.dll, only allow me to download eo.Total. Is it the same? After I added references of dll files, I found an error with EO.Pdf.Internal. How can I solve this problem?


You can either download EO.Total or use our nuget package. You should never download individual DLLs --- we never publish individual DLLs so if you find them online then it is not from us.

See here for more reference:

http://www.essentialobjects.com/doc/common/refdll.aspx

You can not say "I found an error with EO.Pdf.Internal" and expect us to tell you how to fix it. You need to tell us specifically what error you are getting (error message, stack trace, etc).

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.