简体   繁体   English

在同一项目上使用飞碟和docx4j

[英]Using flying saucer and docx4j on the same project

I have a project where I want to be able to format xhtml documents into both PDF format and Docx format. 我有一个项目,希望将xhtml文档格式化为PDF格式和Docx格式。

I've been using flyingsaucer to format PDF documents for some time and always had to use an older version of iText for compatibility reasons. 我一直在使用flyingsaucer来格式化PDF文档一段时间,出于兼容性考虑,总是不得不使用旧版本的iText。 Now that I'm using docx4j I need to update iText to a more recent version or it won't work. 现在,我正在使用docx4j,我需要将iText更新为更新的版本,否则它将无法正常工作。

FlyingSaucer (xhtmlrenderer R8pre2) uses iText 2.0.8 FlyingSaucer(xhtmlrenderer R8pre2)使用iText 2.0.8
docx4j 2.8.0 uses iText 2.1.7 docx4j 2.8.0使用iText 2.1.7

I can only use one iText library but whichever one I use I end up with compatibility issues for either flying saucer or docx4j. 我只能使用一个iText库,但无论使用哪个库,最终都会遇到飞碟或docx4j的兼容性问题。

At the moment the problem seems to come down to one particular method ( com.lowagie.text.pdf.BaseFont.getCharBBox ) which in one version takes a char parameter and in the other it takes an int parameter. 目前,问题似乎可以归结为一种特定的方法( com.lowagie.text.pdf.BaseFont.getCharBBox ),该方法在一个版本中使用char参数,而在另一个版本中则使用int参数。

I think I may have to download sources for either flyingsaucer or iText (I think they're both open source) and fix this myself (not something I've done before but I think I could manage) but I can imagine I'm not the 1st person to run into this problem and perhaps there's another way around it or someone else has already forked one of the projects to resolve this sort of issue. 我想我可能必须下载flyingsaucer或iText的资源(我认为它们都是开源的)并自己解决(不是我以前做过的事,但我想我可以管理),但我可以想象我没有第一个遇到此问题的人,也许有另一种解决方法,或者其他人已经分叉其中一个项目来解决此类问题。

Disclosure: I work on the docx4j project 披露:我从事docx4j项目

docx4j 2.8.0 only uses iText, because it is required by our fork of Flying Saucer , which does the XHTML import. docx4j 2.8.0仅使用iText,因为它是我们的Flying Saucer的fork所必需的,它执行XHTML导入。

In that fork, I added docx related stuff, and removed some stuff we didn't need. 在该分支中,我添加了与docx相关的内容,并删除了一些我们不需要的内容。 It's possible that in the future, we'll offer this back to Flying Saucer - it's a matter of having the time. 将来,我们有可能将其提供给飞碟-时间充裕。

In the meantime I mention for completeness that you can have the real Flying Saucer and our fork on your class path at the same time, since our fork is re-packaged. 同时,为完整起见,我提到您可以在班级路径上同时拥有真正的飞碟和我们的叉子,因为我们的叉子经过了重新包装。

Back to your question, FlyingSaucer proper now has the same 2.1.7 dependency , so if you are able to use the current sources, that should address the issue you have raised. 回到您的问题,FlyingSaucer专有版现在具有相同的2.1.7依赖项 ,因此,如果您能够使用当前资源,那应该可以解决您提出的问题。

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

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