在Java中使用Apache Fop嵌入条形码

时间:2016-08-29 16:05:43

标签: java barcode apache-fop

我使用Apache Fop生成包含PDF417条形码的pdf文档,当我使用命令行时,它可以工作:

fop -fo source.fo -pdf result.pdf

但是当我使用Java替代品时,条形码显示为空白,日志显示这些警告:

Unknown formatting object "{http://barcode4j.krysalis.org/ns}barcode" encountered (a child of fo:instream-foreign-object}. (See position 88:1266)
Unknown formatting object "{http://barcode4j.krysalis.org/ns}pdf417" encountered (a child of barcode}. (See position 89:45)

我在Maven中包含了这些依赖项:

<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/fop -->
<dependency>
    <groupId>org.apache.xmlgraphics</groupId>
    <artifactId>fop</artifactId>
    <version>2.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/net.sf.barcode4j/barcode4j -->
<dependency>
    <groupId>net.sf.barcode4j</groupId>
    <artifactId>barcode4j</artifactId>
    <version>2.1</version>
</dependency>

我失踪了什么?

提前致谢!

1 个答案:

答案 0 :(得分:2)

答案很简单,而不是使用maven dependecy:

<!-- https://mvnrepository.com/artifact/net.sf.barcode4j/barcode4j -->
<dependency>
    <groupId>net.sf.barcode4j</groupId>
    <artifactId>barcode4j</artifactId>
    <version>2.1</version>
</dependency>

我需要使用:

<!-- https://mvnrepository.com/artifact/net.sf.barcode4j/barcode4j-fop-ext -->
<dependency>
    <groupId>net.sf.barcode4j</groupId>
    <artifactId>barcode4j-fop-ext</artifactId>
    <version>2.1</version>
</dependency>

现在非常明显。谢谢你! :)