java JasperReports 使用 Barcode4j 生成条码 - 库依赖
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13612910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JasperReports Barcode Generation With Barcode4j - Library Dependencies
提问by acostache
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.
我一直在搜索哪些库是生成包含报告的条形码所必需的,使用 JasperReports(版本 4.6.0)和barcode4j,在一个简单的设置/场景中(只有一个报告设计,填写报告,导出为 pdf)所以没什么特别的. 在有点绝望的尝试中,我刚刚添加(使用 Eclipse java 项目,在其构建路径中)iReport 4.6.0 使用的所有库,并尝试生成带有条形码的 pdf 报告。结果是一个不错的 pdf 报告,但没有条形码。
I am interested in Barcode4J library dependencies (so not Barbecue) with JasperReports.
我对 JasperReports 的 Barcode4J 库依赖项(所以不是 Barbecue)感兴趣。
回答by acostache
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:
首先,我有一个简单的报告,它有一个条形码元素(带有barcode4j) - 在这里,根据这个有点相关的答案(我认为这实际上让我走上了正确的道路),我为元素添加了一个样式。我目前的风格和元素是这样的:
<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):
第三,我的库在截图中如下(因为时间不够,添加了一张图片):
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 版本相对应,并且 Barcode 相关库适用于 Barcode4j-2.0。
Regards, Andrei
问候, 安德烈
回答by Fredeye
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
我看到您正在加载 iText 库。为什么不直接使用它来创建您的条形码。查看本页底部的解决方案 -将 iText 条码图像从 CCITT 格式转换为 PNG