How to use transparent SVGs in jasper report and export to pdf

Deadly 提交于 2020-03-25 21:54:10

问题


I'm trying to export jasper report to pdf using partially opaque SVGs, but in the pdf the opaque are solid white-ish.

The image expression is:

<imageExpression><![CDATA[net.sf.jasperreports.renderers.SimpleRenderToImageAwareDataRenderer.getInstance(byte[] data)]]></imageExpression>

In the background it seems jasper is using Apache BatikRenderer and XML Graphics. Here are even examples of transparency support:

https://xmlgraphics.apache.org/fop/trunk/graphics.html#svg

According to this link, transparency should be supported: https://xmlgraphics.apache.org/fop/dev/svg.html

There is even a pdf-example which works with transparency.


回答1:


After looking at how the SVG in the example defined transparency, I noticed my SVGs differed:

In the example "fill-opacity" is used, while my SVGs used simply "opacity".

By changing opacity to fill-opacity in the SVG, the transparency also worked in the pdf generated by jasper. (Related thread svg opacity vs fill-opacity)

Now I faced 2 options: One solution would be to write a script that modifies the svg xml and replaces opacity with fill-opacity. Another option was to see if the source of the SVGs could be changed so that I would get SVGs using fill-opacity in the first place. The source outputting SVGs in my case was matplotlib, and the next question was how to get matplotlib to output SVG with fill-opacity instead of opacity:



来源:https://stackoverflow.com/questions/60545570/how-to-use-transparent-svgs-in-jasper-report-and-export-to-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!