Hello
With Servoy 6.03 i have a webclient form with just one big html-aera, dataprovider = vhtml (a form variable).
I fill the variable with:
vhtml = plugins.VelocityReport.renderTemplate(“PasProdukte.html”, m_produktinfos(), resolution);
m_produktinfos collects the needed informations.
The html-aera looks as expected.
Now i only want to print the vhtml into a pdf so the webclient users can do what they want(save,print,open with).
I don’t know how to code this.
Print button in form header with method ???
Any help welcomed.
If you want to create a PDF via code instead of the viewer you can call the getPDFReport() function which returns the PDF as byte array.
This result you can then save as a binary file using the file plugin, send it via email or store it in a database.
Oh, I see you are talking about webclient.
Then as the wiki page says:
“On web client, use previewReport instead with a PREVIEW.MODE set to PDF as this will return a PDF suitable for printing.”
var viewer = plugins.VelocityReport.previewReport("PasProdukte.html", m_produktinfos(),null,null,PREVIEW.PDF);
The open/download dialog pops up, but the pdf looks like this:
500
The plugin encountered an internal error and was unable to complete your request...
Exception Message:
Can't load the XML resource (using TRaX transformer).
org.xml.sax.SAXParseException: Content is not allowed in prolog.
org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using
TRaX transformer). org.xml.sax.SAXParseException: Content is not allowed in
prolog.
at
org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource
at org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:79)
at
net.stuff.servoy.plugin.velocityreport.PluginProvider.parseContent(PluginProvider.java:
at
net.stuff.servoy.plugin.velocityreport.PluginProvider.doRenderToPDF(PluginProvider.java
at
net.stuff.servoy.plugin.velocityreport.PluginProvider$1.run(PluginProvider.java:722)
Ca
by: javax.xml.transform.TransformerException: org.xml.sax.SAXParseException:
Content is not allowed in prolog.
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource
... 4 more
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown
Source)
... 7 more
Have a good look at your template.
This error tells you you have something before the <?xml tag (the prolog), which is not valid.
Since you do:
vhtml = plugins.VelocityReport.renderTemplate(“PasProdukte.html”, m_produktinfos(), resolution);
before, have a look at the vhtml content, this will show you what’s before the prolog, you need to get rid of that (even if it is a simple blank line!)
And BTW, why the “null, null” in your parameters? And why trying to get the viewer, in web client this method doesn’t return it, it is always null, so:
plugins.VelocityReport.previewReport(“PasProdukte.html”, m_produktinfos(), PREVIEW.PDF);
should work.
When you say “same result” do you mean you get the same exception exactly?
Still “org.xml.sax.SAXParseException: Content is not allowed in prolog.”?
Because I see one thing that the renderer will not like as well: usage of UPPERCASE tags is not allowed especially if you mix them up with lowercase as well).
So you need to use tags instead of
And make sure that all your tags are properly closed.
500
The plugin encountered an internal error and was unable to complete your request...
Exception Message:
Can't load the XML resource (using TRaX transformer).
org.xml.sax.SAXParseException: Content is not allowed in prolog.
org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using
TRaX transformer). org.xml.sax.SAXParseException: Content is not allowed in
prolog.
at
org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource
at org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:79)
at
net.stuff.servoy.plugin.velocityreport.PluginProvider.parseContent(PluginProvider.java:
at
net.stuff.servoy.plugin.velocityreport.PluginProvider.doRenderToPDF(PluginProvider.java
at
net.stuff.servoy.plugin.velocityreport.PluginProvider$1.run(PluginProvider.java:722)
Ca
by: javax.xml.transform.TransformerException: org.xml.sax.SAXParseException:
Content is not allowed in prolog.
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource
... 4 more
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown
Source)
... 7 more
Is your template UTF-8 (or 16)?
Can you make sure that you don’t have a UTF-BOM as a first character?
If your document has one, this will also give you this error…
I’ve committed a change to the VelocityReport plugin - v1.5.8 - to deal with Unicode BOM. The templates are read and if they contain BOM bytes, these are stripped from the input using a spcial Reader.
This should fix your issue without even changing your file encoding: https://www.servoyforge.net/news/190