Welcome Guest Search | Active Topics | Sign In | Register

EO.PDF slow loading (javascript issue) Options
Kevin Sebastin
Posted: Thursday, June 11, 2020 8:33:57 AM
Rank: Newbie
Groups: Member

Joined: 5/29/2020
Posts: 6
Hi, we have an issue with page data not being rendered on an Angular application we are trying to make PDFs from using url conversion.

The suggestions provided on the documentation pages do not fully meet our requirements:

As our PDFService is a stand-alone service, that recieves either html raw or an url as target, the solution to switch to manually triggered pdf generating, would mean imposing specific javascript on all pages as well as requiring the developers to know beforehand, that this particular page needs to made PDF ready. This would kill the idea of having a centralised all-purpose PDF service (within the scope of our company).

The suggestion to use min-wait-time is also not without severe drawbacks. The target pages to be converted into PDF may vary from single page to many, data-"heavy" pages. Thus in order to be sure, we would need to impose a min. wait time of several seconds. Data doesnt load that slow, but if we go close to the actual load time, eo.pdf begins conversion before data is ready anyway.

Making rendering of the dynamic portions of the page dependant on data-fetch being completed doesnt work either.

There must be a specific event that triggers the conversion when trigger is set to Auto - if we knew what exactly triggers the conversion on auto, we might be able to delay that event untill all data is loaded.

So the question is, what is the exact event triggering PDF conversion?

Kind Regards

eo_support
Posted: Thursday, June 11, 2020 4:15:30 PM
Rank: Administration
Groups: Administration

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

When the triggering mode is set to auto, the conversion would wait for the main page and all images to be loaded before starting the conversion.

When you use Angular to dynamically load page contents, this condition will be met very quickly since the initial page contains minimum information and the real contents are only loaded later. There is no reliable way for the converter to detect when the "real contents" has arrived.

One thing you can try to do is to use an HtmlToPdfSession object:

https://www.essentialobjects.com/doc/eo.pdf.htmltopdfsession.aspx

Then follow these steps:

1. Load a web page using LoadUrl/LoadHtml method;
2. Run JavaScript code using ExecScript method to perform certain checks such as:
2.a. Whether the document has been loaded;
2.b. Whether all images have been loaded;
2.c. Whether the page uses Angular;
3. You can then use the result of step 2 to derive a more "intelligent" waiting strategy. You may need to loop back to step 2 again after you have waited for a certain amount of time. Use EO.WebBrowser.WebView.DoEvents(time_out) to wait;
4. When you are ready to convert, call RenderAsPDF to convert the result;

Please let us know if this works for you.

Thanks!
Kevin Sebastin
Posted: Friday, June 12, 2020 7:18:15 AM
Rank: Newbie
Groups: Member

Joined: 5/29/2020
Posts: 6
Thank you for your suggestion.

I will give it a go and post results here.

Another method is using Angular Resolve ( https://angular.io/guide/router#resolve-pre-fetching-component-data ) - this also does the trick at least for our current issue; you simply preload data before final navigation.

However, your suggestion is general so I think we will use both (not all clients are Angular or for that matter within our developer control).
eo_support
Posted: Friday, June 12, 2020 9:59:01 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
You are very welcome! Please feel free to let us know if there is anything else.


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.