Welcome Guest Search | Active Topics | Sign In | Register

Blank PDFs when generating locally after upgrade from Angular 16 to Angular 18 Options
Phil
Posted: Thursday, December 5, 2024 4:04:52 AM
Rank: Advanced Member
Groups: Member

Joined: 11/8/2017
Posts: 66
Hi, an issue when generating PDF's locally seems to have emerged after upgrading our Angular project from version 16 to 18 - a few notes

- we are using EO-PDF version 2024.2.81
- we are running Angular 18.2.13
- the problem only occurs locally (i.e. within a Visual Studio debug session on our local machines) - after we deploy onto our AppServices slots and test the PDF's they generate fine
- when we deploy to our AppServices slots, Angular enableProdMode is set, and it is an "aot" build
- locally I have tried with *and* without enableProdMode set and being and *not* being an "aot" build, however the problem occurs regardless
- the problem occurs with medium to large templates however the larger the template, the more likely the issue is evident - for small templates, the PDF seems to generate every time
- on those occasions when the issue occurs, the Angular lifecycle hooks (like ngOnInit, ngAfterViewInit) don't seem to be invoked - the console logs in the Angular template (captured via HtmlToPdf.DebugConsole) show that console.log statements just inside the hooks are not in the EO-PDF log
- we have one template that invokes the tool within (ie. eoapi.convert(), HtmlToPdfOptions.TriggerMode = HtmlToPdfTriggerMode.Dual) - this seems to generate the PDF correctly each time hence we could use this strategy, however we have 100's of templates that would require change, and hence we would rather avoid
- there are no errors/exceptions being thrown by our application or EO-PDF
- there looks to be plenty of resource (CPU/memory) availability - when we flick back to Angular 16 (without rebooting, no closing down of apps previously open, etc) we can generate PDF's locally without an issue

As far as you know, has this been an issue for anyone else ? We're not sure where to go with this - we can't really deploy if we can't recreate issues locally if/when they arise - is there a way we can make sure EO-PDF unconditionally acknowledges/initiates the Angular life-cycle hooks if they are there ?
eo_support
Posted: Thursday, December 5, 2024 10:28:46 AM
Rank: Administration
Groups: Administration

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

This looks like Angular used some kind of delay loading mechanism through JavaScript and EO.Pdf started conversion before such loading is completed. In such case the only way to have reliable result is to detect when the JavaScript code in your page has really finished loading and notify EO.Pdf through eoapi.convert().

You do not have to modify all your templates to achieve this. You can do it through this property:

https://www.essentialobjects.com/doc/eo.pdf.htmltopdfoptions.jsinitcode.html

With this property you can inject some JavaScript into every page EO.Pdf loads. Inside your JavaScript code you can monitor Angular's life cycle events and only trigger the conversion when a specific event is received.

Please keep in mind that JSInitCode is run before everything else in the page. So you must have some kind of delay mechanism in order for it to interact with Angular code. For example, you could use setTimeout to delay check whether Angular has been loaded and only carry out additional logic once it has been loaded.

Hope this helps. Please feel free to let us know if you still have any more questions.

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.