Page 1 of 1

Printing NG Client with Velocity

PostPosted: Tue Feb 16, 2016 1:55 pm
by Gordon McLean
Hi
I am trying to print a report using the Velocity Reports Plugin within servoy NG Client.

works as expected and previews the report
plugins.VelocityReport.previewReport(template,context)

show the printer dialogue but fails to print
plugins.VelocityReport.printReport(template, context)

Is there a problem with printing from NG Client and if so is there any workaround ? The solution is needed for an exhibition and one of the features is to print the customers order so print is kind of critical.

IF this is not possible is there a way to print from a headless client as we will have a mini server on the stand

Cheers
Gordon

Re: Printing NG Client with Velocity

PostPosted: Tue Feb 16, 2016 10:45 pm
by ptalbot
You cannot print directly in a browser, you will not see the printer dialog there. This would be true of a web client where Velocity usually renders a html page and send it back, for the user to use the "print" option of the browser.

What happens in your cae is that velocity doesn't understand that it is called from a NGClient (it has no knowledge of it) so it "believes" it is handled from a Smart client instead, and the printer dialog is actually called from developer. This will never work on a server.

What you need to do is to generate a PDF, using plugins.VelocityReport.getPDFReport(template, context) to generate the PDF bytes and then send it back to the client using the file plugin for example.

Re: Printing NG Client with Velocity

PostPosted: Wed Feb 17, 2016 8:50 am
by Gordon McLean
ok thank you understood, I did wonder why the print dialogue was triggered and that makes sense. So in this case the challenge it either to save it and get the server to print it with a script or more normally save it and display the result in a separate tab in the browser.

Many thanks
Gordon

Re: Printing NG Client with Velocity

PostPosted: Thu May 25, 2023 1:01 pm
by rieder
Hi

Despite all the helpful information, I cannot get the "print" to work as expected.

I call getPDFReport with the same template used for preview in smart client. And the same context.
The image-url of the diagram, which I want to print, is valid, if I embed it in a html page, the image of the diagram is displayed correctly.

After generating the pdf, I save it as a file. The PDF looks, as if the content is not rendered: The data is just added inline, no format, no tag resolved, the image url is just text.

Any idea, what is wrong?

Thank you and kind regards
Birgit

Re: Printing NG Client with Velocity

PostPosted: Thu May 25, 2023 4:15 pm
by ptalbot
When html tags are added as is, it is generally because Velocity treats any text data as text, and transforms <, >, & into their html entities.
To prevent that on specific values, you can use the htmlize helper object, in the template, or use the #h() macro which is a shortcut for it *

Say the context object provided to getPDFReport is something like { img: '<img src="http://test.com/image/image.png"/>' }

You will need to use
$htmlize.get($img) or $htmlize[$img]
or
#h($img)
in your template to render it as true html.

* Note that the definition for that macro is in the VM_global_library.vm file provided with the Velocity plugin, this file should be placed at the root of the reports folder you are pointing to with velocityreport.reportFolder.

Re: Printing NG Client with Velocity

PostPosted: Thu May 25, 2023 8:15 pm
by rieder
Dear Patrick

That was the trick! htmlize solved it, the chart is displayed as expected.
Thank you so much! After spending hours and hours that was a 1 minute task now.

Best regards
Birgit