fabianobonin Posted March 10, 2016 Posted March 10, 2016 Hi, i am exporting a report to SVG using batik SVGGraphics2D and JRGraphics2DExporter. JasperPrint jasperPrint = ... Document document = GenericDOMImplementation.getDOMImplementation() .createDocument(SVGConstants.SVG_NAMESPACE_URI, "svg", null); SVGGraphics2D graphics2d = new SVGGraphics2D(document); graphics2d.setUnsupportedAttributes(null); JRGraphics2DExporter exporter = new JRGraphics2DExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(0)); exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics2d); exporter.exportReport();[/code]But the text of the report is being exported as a SVG path, not as a SVG text.It should export somethig like this:<text x="10" xml:space="preserve" y="10" style="stroke:none;">Teste</text>[/code]But it is exporting somethig like this:<path d="M29.4531 236.5496 Q29.1406 236.7058 28.8516 236.7839 Q28.5625 236.8621 28.2344 236.8621 Q27.8125 236.8621 27.4688 236.7449 Q27.125 236.6277[/code]What makes the generated file, which should have few kB, to have many mB.I did some tests with batik SVGGraphics2D to make sure it is rendering text as text, and i can confirm it is working as expected. graphics2d.setFont(new Font("Arial", Font.PLAIN, 12)); graphics2d.drawString("Teste", 10, 10); graphics2d.drawRect(0, 0, 100, 100);[/code]So, my question is:Is it possible to configure JRGraphics2DExporter to export text as text? (it is just a matter of using Graphics2D's method drawString to draw text)I presume there must be a way, since when we export a report to PDF text are exported as text, not paths or images.Regards,Fabiano
lucianc Posted March 11, 2016 Posted March 11, 2016 Texts are rendered as paths with SVGGraphics2D because the JasperReports AWT text renderer calls Graphics2D.drawGlyphVector (via java.awt.font.TextLayout).There is no configuration to change this behaviour. The PDF exporter is different exporter.You could try a customization by changing (or extending) JR's AwtTextRenderer.draw() method to do grx.drawString(segment.as.getIterator(), x + drawPosX, y + topPadding + verticalAlignOffset + drawPosY) instead of segment.layout.draw(..) That seems to work at least in simple cases, but I'm not fully confident that it works in all cases. Do some tests to be sure that it does what's expected. Regards,Lucian
fabianobonin Posted March 13, 2016 Author Posted March 13, 2016 Hi, Lucian!Thanks for your answer.I have been exporting reports to both PDF and SVG, and it seems PDF exporter is much more mature than SVG exporter, am i right?I would like to contribute to improve SVG exporter, maybe not as a coder, but as a sponsor. Is it possible to be the sponsor of a feature in this community?I am searching for a 100% java way to generate a report with jasperreports, serialize it to some standard format, store or transfer it to another machine, and print it later (or in the destination machine) without needing jasperreports in this last step.Off course, the first format that comes to mind is PDF, but i still didn't find a 100% java way to print a PDF file to a non PDF printer.The options i found was Ghost4J (that needs an external C library), PDFBox, PDF Renderer (both PDFBox and PDF Renderer messed with the original report during convertion), or to use a external PDF program to print (which needs a platform dependent application). All alternatives or are not 100% java compatible or generates poor conversions when printing (tried other pdf renderers also).So i came to SVG. It is a well known format, compact, can be stored, transfered, and we have the batik library that can be used later to print, to generate a image, or whatever, without the need of the jasperreports library and with a 100% java solution.It is just my opinion, but i think SVG should be promoted to one of the main formats, together with PDF, and have a rock solid converter!What do you think about?Best regards,Fabiano
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now