Printing NG Client with Velocity

Questions and answers on developing, deploying and using plugins and JavaBeans

Printing NG Client with Velocity

Postby Gordon McLean » Tue Feb 16, 2016 1:55 pm

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
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: Printing NG Client with Velocity

Postby ptalbot » Tue Feb 16, 2016 10:45 pm

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.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Printing NG Client with Velocity

Postby Gordon McLean » Wed Feb 17, 2016 8:50 am

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
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: Printing NG Client with Velocity

Postby rieder » Thu May 25, 2023 1:01 pm

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
Birgit Rieder
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
rieder
 
Posts: 177
Joined: Thu Jan 26, 2012 5:18 pm

Re: Printing NG Client with Velocity

Postby ptalbot » Thu May 25, 2023 4:15 pm

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.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Printing NG Client with Velocity

Postby rieder » Thu May 25, 2023 8:15 pm

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
Birgit Rieder
7r AG, Switzerland
SAN Developer
http://www.seven-r.ch
User avatar
rieder
 
Posts: 177
Joined: Thu Jan 26, 2012 5:18 pm


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 9 guests