Defect #1598
HTML rendering in PDF/Velocity not working since start of version 3.8
0%
Description
I want to upgrade to latest plugin. But with the start of plugin version 3.8 I have problems with injected HTML into the velocity-report.
injected HTML is sometimes rendered and sometimes shows as plain text. See attached PDF as example.
What is changed from version 3.7.12 and > 3.8....
Files
History
Updated by Patrick Talbot 16 days ago
How do you embed the html? I suppose this is coming from variables in the context you pass to Velocity?
If so, do you use the #h() macro (provided you have placed the VM_global_library.vm file in your report folder) or $!htmlize.get() / $!htmlize[] in your template for these variables?
Typically, Velocity will escape < and > as $lt; and $gt; respectively, but when you use the #h() macro, this reverts the escaping (IF the html is well-formed)...
So instead of using $someHTML or $!someHTML in your template, try using #h($!someHTML) or $htmlize.get($!someHTML) and this should work.
If not, let me know.
Updated by Sjoerd Hannema 16 days ago
I use in the templates #h(!someHTML). In the reports directory the file VM_global_library.vm is placed. The HTML is put in the context data or sometimes in a Servoy calculation.
Everything was working perfect for years. Only after plugin version 3.8 it is not working anymore. The strange thing is that sometimes the HTML is placed OK.
Template: #h($!shp_addressblock)
I have tried: $htmlize.get($!shp_addressblock) --> Also not working. Gives the same result.
For example the addressblock html is strange. The HTML <b> </b> is put as text in the PDF and the <br /> is put as HTML. Both in the same #h($!shp_addressblock)
Updated by Patrick Talbot 16 days ago
Yes, $htmlize.get() is the same as #h() - #h() is a shortcut to the htmlize.get() function.
Please test with v3.9 and let me know. If this doesn't work, I will need a template + a json file of the context you are passing to the template (you can do a JSON.stringify(context); save this in a file and attach to this ticket with the template file, that will allow me to check what's going on.
Updated by Patrick Talbot 16 days ago
I just checked your PDF file again, and it looks like the problem comes from the fact that the html that you inject is not proper xHTML, so the #h()/$htmlize.get() function is detecting this and instead of accepting to unescape the < and > it doesn't, it only convert line return and keeps the <br/> if present.
One <table> is appended before the first table is closed and it is placed where you would normally expect a <tr>, this is wrong and no PDF can reliably be produced out of it. See the capture to see where the HTML is badly structured.
In previous versions of Velocity, you would have had an exception and the PDF would not have been produced.
In versions 3.8+ the #h()/$html.get() attempts to still output a PDF, but escapes the bad HTML, this is why you get the PDF you have.
Fix the HTML (make it propert xHTML) and this will work.
Updated by Sjoerd Hannema 15 days ago
Hello Patick,
Version 3.9 is working OK.
There was indeed an error in the injected HTML.
Strange that it was accepted till version 3.7 but I think the new version > 3.8 is more strict with injected html.
It was already working for years. But the html was not OK.
I did also use for spaces sometimes the "& nbsp ;" That is also not accepted anymore. So I have changed that to < pre >< / pre >
Everything is now working with the plugin version 3.9.
Thanx for your guidance!
Updated by Patrick Talbot 15 days ago
- Status changed from New to Resolved
Good to know you fixed the issue on your end and that v3.9 is working for you.
I think the xHTML parser itself is more strict, but this is the one that Servoy ships with its distribution (fs-parser.jar) so I had to keep in synch with it.