用最新的iText 7.0.1替换JasperReport iText 2.1.7 [英] Replace JasperReport iText 2.1.7 with latest iText 7.0.1

查看:121
本文介绍了用最新的iText 7.0.1替换JasperReport iText 2.1.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用JasperReport 6.1.0,它依赖于com.lowagie:itext:jar:2.1.7.js2. iText 2.1.7似乎有IP问题,iText要求所有用户使用需要商业许可证的最新版本.因此,我们想购买iText许可证.现在,iText的最新版本是7.0.1.我尝试执行以下步骤,用最新的iText 7.0.1替换JasperReport的iText 2.1.7:

We are using JasperReport 6.1.0 which has a dependency to com.lowagie:itext:jar:2.1.7.js2. It looks like iText 2.1.7 has IP issue, and iText is asking all users to use the latest version which requires a commercial license. So we would like to buy iText license. Now iText latest version is 7.0.1. I tried did below steps to replace JasperReport's iText 2.1.7 with latest iText 7.0.1:

<dependency>
  <groupId>net.sf.jasperreports</groupId>
  <artifactId>jasperreports</artifactId>
  <version>6.1.0</version>
  <exclusions>
    <exclusion>
      <groupId>com.lowagie</groupId>
      <artifactId>itext</artifactId>
    </exclusion>
    ...

2.在pom.xml中添加新的iText jars

<dependency>
  <groupId>com.itextpdf</groupId>
  <artifactId>barcodes</artifactId>
  <version>7.0.1</version>
  <!-- barcodes depends on kernel -->
</dependency>
<dependency>
  <groupId>com.itextpdf</groupId>
  <artifactId>font-asian</artifactId>
  <version>7.0.1</version>
</dependency>
<dependency>
  <groupId>com.itextpdf</groupId>
  <artifactId>forms</artifactId>
  <version>7.0.1</version>
  <!-- forms depends on kernel and layout -->
</dependency>
<dependency>
  <groupId>com.itextpdf</groupId>
  <artifactId>hyph</artifactId>
  <version>7.0.1</version>
</dependency>
<dependency>
  <groupId>com.itextpdf</groupId>
  <artifactId>io</artifactId>
  <version>7.0.1</version>
</dependency>
<dependency>
  <groupId>com.itextpdf</groupId>
  <artifactId>kernel</artifactId>
  <version>7.0.1</version>
  <!-- kernel depends on io -->
</dependency>
<dependency>
  <groupId>com.itextpdf</groupId>
  <artifactId>layout</artifactId>
  <version>7.0.1</version>
  <!-- layout depends on kernel -->
</dependency>
<dependency>
  <groupId>com.itextpdf</groupId>
  <artifactId>pdfa</artifactId>
  <version>7.0.1</version>
  <!-- pdfa depends on kernel -->
</dependency>
<dependency>
  <groupId>com.itextpdf</groupId>
  <artifactId>sign</artifactId>
  <version>7.0.1</version>
  <!-- sign depends on kernel, layout and forms -->
</dependency>

3.运行mvn并测试报告功能,出现以下错误:

2016-11-17 14:43:36,520错误[c.i.c.d.DeferredOperationManager] [Thread-49]延迟操作异常.操作UUID:2a647922-d6d0-450d-9b2d-4d97638ba03f. UI错误密钥:d9a16093-be20-4278-9f8b-93120c0a2231-错误:java.lang.NoClassDefFoundError:com/lowagie/text/SplitCharacter

2016-11-17 14:43:36,520 ERROR [c.i.c.d.DeferredOperationManager] [ Thread-49] Exception on Deferred Operation. Operation UUID: 2a647922-d6d0-450d-9b2d-4d97638ba03f. UI Error key:d9a16093-be20-4278-9f8b-93120c0a2231 - Error: java.lang.NoClassDefFoundError: com/lowagie/text/SplitCharacter

JasperReport似乎正在尝试查找名称空间为"com.lowagie ..."的旧iText类. 我试图解压缩新的iText 7.0.1 jar,这些类在"com.itextpdf ..."包中.

It looks like JasperReport is trying to find old iText classes which namespace is "com.lowagie...". I tried to unzip the new iText 7.0.1 jar, the classes are in package "com.itextpdf...".

如何使JasperReport调用新的iText jar?

How can I make the JasperReport call the new iText jar?

推荐答案

您不能将iText 2.1.7替换为iText 7,因为两个版本之间的差异太大.我们确实知道有些人开始将iText 5与JasperReports结合使用.这就需要对JasperReports进行许多更改,例如将包名称从com.lowagie更改为com.itextpdf(*),并将对com.lowagie.text.Color的引用更改为com.itextpdf.text.BaseColor.

You can not replace iText 2.1.7 with iText 7 because the differences between the two versions are too big. We do know of some people who moved to using iText 5 with JasperReports. That requires a number of changes to JasperReports such as changing the package names from com.lowagie to com.itextpdf (*) and changing references to com.lowagie.text.Color to com.itextpdf.text.BaseColor.

在iText上,我们注意到使用iText 5达到了极限.例如:我们使用char存储文本,这意味着每个字符仅使用2个字节存储.如果我们要支持印地语,那还不够.如果要向iText添加对印度语的支持,我们必须重写完整的字体层. iText 5中的替换字体层"确实非常困难,因为字体层是构建所有其余代码的基础.因此,我们决定重写完整的API.

At iText, we noticed that we were hitting the ceiling with iText 5. For instance: we store text using char which means that each character is stored using only 2 bytes. That wasn't sufficient if we wanted to support Hindi. We had to rewrite the complete font layer if we wanted to add support for Indic languages to iText. "Replacing the font layer" in iText 5 would have been really difficult since the font layer is the foundation on which all the rest of the code is built. Hence our decision to rewrite the complete API.

您可以在此处观看有关此决定的更多详细信息的视频: Devoxx 2016:糟糕我破坏了我的API"

You can watch a video that goes into more detail regarding this decision here: Devoxx 2016: "Oops I broke my API"

但是:用iText 7替换iText 2.1.7的最大问题是JasperReports依赖于PdfGraphics2D,我们还没有将该部分移植到iText 7.我们甚至可能决定不移植该部分,因为如果您选择使用PdfGraphics2D(并且PDF/UA变得越来越重要),就不可能创建PDF/UA.

However: the biggest problem with replacing iText 2.1.7 with iText 7, is that JasperReports depends on PdfGraphics2D and we haven't ported that part to iText 7 (yet). We might even decide not to port that part ever, because it is impossible to create PDF/UA if you choose to use PdfGraphics2D (and PDF/UA is getting more and more important).

(*)在2009年,我决定从包裹名称中删除我的名字.当我第一次发布iText时,我只拥有lowagie.com域,并且我为编写的所有Java代码使用了com.lowagie包.我没想到iText会如此成功.当每个人都开始使用iText时,每个人都开始亲自问我问题.我已经没有生命了.因此,我创建了一家公司,我们对iText进行了专业化处理,并用更中性的com.itextpdf代替了com.lowagie.

(*) In 2009, I decided to remove my name from the package names. When I first released iText, I only owned the lowagie.com domain, and I used com.lowagie packages for all the Java code I wrote. I didn't expect iText to become such a success. When everyone started to use iText, everyone started to ask me questions personally. I didn't have a life anymore. Hence I created a company, we professionalized iText and replacing com.lowagie with the more neutral com.itextpdf was one of those professionalizations.

这篇关于用最新的iText 7.0.1替换JasperReport iText 2.1.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆