JasperReports Barcode Generation With Barcode4j - Library Dependencies

冷暖自知 提交于 2019-12-12 18:49:49

问题


I have been searching which libraries are necessary to generate a barcode containing report, using JasperReports (version 4.6.0) and barcode4j, in a simple setting/scenario (just have a report design, fill the report, export to pdf) so nothing fancy. In a somewhat desperate try, I just added (using an Eclipse java project, in its build path) all libraries used by iReport 4.6.0, and tried to generate a pdf report with a barcode in. The result was a nice pdf report, but with NO barcode in.

I am interested in Barcode4J library dependencies (so not Barbecue) with JasperReports.


回答1:


Finally, i found a somewhat more complex approach i think (i am sure this could be done simpler)

First, i have a simple report that has a barcode element (with barcode4j) - here, according to this somewhat related answer (which actually got me on a right trail i think), i have added a style to the element. My current style and element are like this:

<style name="Barcode" mode="Opaque" forecolor="#000066" backcolor="#FFFFFF" fill="Solid" hAlign="Left" vAlign="Top" markup="styled" fontName="SansSerif" fontSize="11"/>
...
<componentElement>
<reportElement uuid="e70dd866-d0a9-4b34-8fb1-0f0b04c9dcf3" style="Barcode" x="453" y="0" width="78" height="38" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true"/>
<jr:Code128 xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<jr:codeExpression><![CDATA["123456789"]]></jr:codeExpression>
</jr:Code128>
</componentElement>

I am sure several styling things may be removed (but i think from previous experience markup styled is important).

Secondly, i have a code as follows to generate the pdf report exported with JasperReports:

JasperReport jasperReport = JasperCompileManager.compileReport("report.jrxml");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(jasperPrint, "result.pdf");

Thirdly, the libraries i have are as follows in the screenshot (adding a picture due to lack of time):

Hope this will help others as well - optimizations, corrections, improvements (to make this more concise and optimal) are most welcome.

NOTE: the used versions of JasperReports libraries are corresponding to their 4.6.0 version and also Barcode related libraries are for Barcode4j-2.0.

Regards, Andrei




回答2:


I see you're loading the iText library. Why not just use this for creating your barcodes. Checkout the solution at the bottom of this page - Convert iText Barcode Image from CCITT format to PNG



来源:https://stackoverflow.com/questions/13612910/jasperreports-barcode-generation-with-barcode4j-library-dependencies

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