简体   繁体   English

JasperReports使用Barcode4j生成条形码 - 库依赖关系

[英]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. 我一直在寻找哪些库来生成包含报告的条形码,使用JasperReports(版本4.6.0)和barcode4j,在一个简单的设置/场景中(只需要一个报表设计,填写报表,导出为pdf)所以没什么特别的。 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. 在一个有点绝望的尝试中,我刚刚添加(使用Eclipse java项目,在其构建路径中)iReport 4.6.0使用的所有库,并尝试生成带有条形码的pdf报告。结果是一个很好的pdf报告,但没有条形码。

I am interested in Barcode4J library dependencies (so not Barbecue) with JasperReports. 我对使用JasperReports的Barcode4J库依赖项(因此不是烧烤)感兴趣。

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. 首先 ,我有一个简单的报告,它有一个条形码元素(带有barcode4j) - 在这里,根据这个有点相关的答案 (实际上让我想到了正确的道路),我已经为元素添加了一个样式。 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: 其次 ,我有一个如下代码来生成使用JasperReports导出的pdf报告:

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库的依赖

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. 注意 :JasperReports库的已使用版本与其4.6.0版本相对应,条形码相关库也适用于Barcode4j-2.0。

Regards, Andrei 此致,安德烈

I see you're loading the iText library. 我看到你正在加载iText库。 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 查看本页底部的解决方案 - 将iText Barcode Image从CCITT格式转换为PNG

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM