javajasper-reportsbarcodebarcode4j

JasperReports Barcode Generation With Barcode4j - Library Dependencies


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.


Solution

  • 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):

    eclipse library depedencies

    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