Semi-transparent (translucent) background color ignored in jasper reports pdf export

╄→гoц情女王★ 提交于 2019-12-24 03:54:14

问题


Q: Why is the alpha information lost when saving to PDF?

Jaspersoft studio doesn't allow me to specify colors with alpha. So I tried to be clever and specified keys on my shading elements and changed the color in the code like so:

JasperReport jasperReport = (JasperReport) JRLoader.loadObject(getClass().getResourceAsStream("/reports/Test.jasper"));
((JRStaticText) jasperReport.getGroups()[0].getGroupHeaderSection().getBands()[0].getElementByKey("bg")).setBackcolor(new Color(0, 0, 0, 30));
((JRRectangle) jasperReport.getGroups()[0].getGroupFooterSection().getBands()[0].getElementByKey("bg")).setBackcolor(new Color(0, 0, 0, 30));

Just to see if it makes a difference I used both JRStaticText and JRRectangle. The preview and the physical printout on paper look great. It also works when I print to PDFCreator. But when I save to PDF from the JRViewer/JasperViewer, the resulting PDF appears with opaque black.

Preview/Paper print/PDFCreator:

Jasper reports PDF save/export:


回答1:


Apparently this feature is not supported by Jasper Reports.

Jasper Studio 6.1 even allows to specify a Text field transparency level in the background color dialog box, only to lose the value as soon as the dialog is given the OK.

The solution we implemented was to overlap the text with a semi-transparent image prepared previously.



来源:https://stackoverflow.com/questions/29458133/semi-transparent-translucent-background-color-ignored-in-jasper-reports-pdf-ex

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