Home
Analytics
Report Item as SVG
kosta
Hello BIRT Community,
does someone had created a report item that's producing scalable vector graphics (svg) to an PDF output?
The tutorial which I found on the web has good explanation how to create report items as png image but I need svg because embedding them to a PDF are looking much better.
Thanks in advance for suggestions or hints.
Find more posts tagged with
Comments
CBR
What kind of report items do you mean? You can add svg images to your report and you can output charts as SVGs.
Which version of BIRT are you using? BIRT 2.6.2 and BIRT 3.7 are supporting SVG in PDF. If you are using BIRT WebViewer 3.7 Charts are rendered as SVG as default. If you are using BIRT 2.6.2 the WebViewer doesn't generates Charts as SVG by default in PDF. Try adding &__svg=true to render Charts as SVG in PDF.
Please note that you have to change output image format to SVG in the designer in both scenarios. If it is set to some else format BIRT will generate the report in that format.
If you are using some earlier version BIRT will not output any chart as SVG in PDF.
kosta
Hello cbell,
thanks for the answer.
I have custom report item which is implemented as eclipse plugin.
I followed the tutorial which can be seen here:
http://www.eclipse.org/articles/article.php?file=Article-BIRT-ExtensionTutorial1/index.html
http://www.eclipse.org/articles/article.php?file=Article-BIRT-ExtensionTutorial2/index.html
In thouse examples a rotated text is created as png.
It would be nice to know how is it possible to create svg images from a custom report item.
This examples are the only i found on the net and are the same like in the BIRT book.
Thanks for any further hint and suggestion.
zqian
kosta,
To output SVG, you just simply alter your ReportItemPresentationImpl, overwrite getImageMIMEType() to return "image/svg+xml" and implement the logic in onRowSet() to return an svg content stream. Note not all emitters support SVG, so you may need check the output format passed in by setOutputFormat().
kosta
Thank you zqian for the answer.
What kind of object can the "svg content stream" be?
I am creating the images with apache batik, but then using trascoders to translate over the PNGTranscoder to java OutputStream.
Now I dont need the PNG or JPEG or TIFF transcoder, but I need to translate the document into valid stream for returning it.
Thank you.
zqian
Basically the svg content stream is an xml document stream.
kosta
The getOutputType() method should still return OUTPUT_AS_IMAGE?
with setOutputFormat() I can set the format for the output for wich this output shoul be valid.
i.e. setting it to "pdf" would mean "only for pdf output"?
kosta
Hello BIRT Community,<br />
<br />
using this piece of code I could transform the document into byte stream:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
OutputStream ostream = baos;
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(ostream);
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.transform(source, result);
} catch (TransformerException e) {
e.printStackTrace();
}
</pre>
<br />
<strong class='bbc'>Note</strong>: I was using the batik libs from the eclipse plugin folder and they threw abstract method exception (using the libs from the apache batik site - 1.7 version - solve the problem):<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
Caused by: java.lang.AbstractMethodError
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(DOM2TO.java:373)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:127)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:94)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:661)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:707)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
...
</pre> <br />
<br />
After that the bytes from the output stream were copied to an byte input stream to be finally returned as return of the method "onRowSets".<br />
<br />
In the HTML preview i couldnt see the images (looking at the log I could see svg=false) but the pdf were created with the for me familiar image but not like I was expecting as part of the pdf itself but as jpeg.<br />
<br />
It seems the image is converted from BIRT elsewhere into jpg. Can this be avoided somehow?<br />
<br />
Thanks in advance.
zqian
For html output, you may need ensure the svg=ture flag is passed in, otherwise the SVG content will be discarded. For other emitters, it depends on whether the emitter supports the svg content or not. i.e. the emitter may convert the svg content to other format or simply discard it.
kosta
I am working with the PDF emmiter.
When embedding images as SVG or creating charts als SVG output everything is fine.
There is anomaly about images. if the image size if different from the original the image will be transformed into png or jpeg.
But creating SVG from custom item always returnes jpeg.
I came to an Idea to make the same like in the custom item but with the chart api.
btw. who is developing the PDF emmiter?
qos
Kosta,
I'm extremely interested in the rotated text plugin with SVG output for PDF that you seem to be developing.
Have you reached anything usable and are you willing to share it?
Could I help in any way?
Thanks in advance