【问题标题】:JasperReports Barcode Generation With Barcode4j - Library DependenciesJasperReports 使用 Barcode4j 生成条码 - 库依赖项
【发布时间】:2012-11-16 18:24:09
【问题描述】:

我一直在搜索生成包含条码的报告所需的库,使用 JasperReports(版本 4.6.0)和barcode4j,在一个简单的设置/场景中(只要有一个报告设计,填写报告,导出为 pdf)所以没什么特别的。 在有些绝望的尝试中,我刚刚添加了(使用 Eclipse java 项目,在其构建路径中)iReport 4.6.0 使用的所有库,并尝试生成带有条形码的 pdf 报告。结果是一个不错的 pdf 报告,但没有条形码。

我对 JasperReports 的 Barcode4J 库依赖项(所以不是 Barbecue)感兴趣。

【问题讨论】:

    标签: java jasper-reports barcode barcode4j


    【解决方案1】:

    最后,我发现了一种我认为更复杂的方法(我相信这可以做得更简单)

    首先,我有一个简单的报告,其中包含一个条形码元素(带有barcode4j)-在这里,根据somewhat related answer(我认为这实际上让我走上了正确的道路),我有为元素添加样式。我现在的样式和元素是这样的:

    <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>
    

    我确信可能会删除一些样式设置(但我认为根据以前的经验标记样式很重要)。

    其次,我有如下代码来生成使用 JasperReports 导出的 pdf 报告:

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

    第三,截图中我拥有的库如下(由于时间不够,添加图片):

    希望这对其他人也有帮助 - 最欢迎优化、更正、改进(以使其更简洁和最佳)。

    注意:使用的 JasperReports 库版本对应 4.6.0 版本,Barcode 相关库适用于 Barcode4j-2.0。

    问候, 安德烈

    【讨论】:

      【解决方案2】:

      我看到您正在加载 iText 库。为什么不直接使用它来创建您的条形码。查看本页底部的解决方案 - Convert iText Barcode Image from CCITT format to PNG

      【讨论】:

        猜你喜欢
        • 2014-03-29
        • 1970-01-01
        • 2014-06-05
        • 1970-01-01
        • 1970-01-01
        • 2012-06-25
        • 1970-01-01
        • 2014-04-16
        • 1970-01-01
        相关资源
        最近更新 更多