Java generates complex word/pdf solutions

Based on the java export word and pdf solutions given on the Internet, I will now provide you with the solution I am using;

First review the content on the Internet;

Common export word solutions

1. Jacob is the abbreviation of Java-COM Bridge, which builds a bridge between Java and Microsoft COM components. Use Jacob's own DLL dynamic link library, and realize the call of COM program on the Java platform through JNI. The generation of DLL dynamic link library needs the support of windows platform.

2. Apache POI includes a series of APIs, which can operate various format files based on MicroSoft OLE 2 Compound Document Format, and can read and write Excel, Word and other files in Java through these APIs. His excel processing is very powerful, and the word is still limited to reading. Currently, it can only implement some simple file operations, and cannot set styles.

3. Java2word is a component (class library) that calls MS Office Word documents in a java program. This component provides a set of simple interfaces for the Java program to call its services to operate Word documents.
These services include: opening documents, creating new documents, finding text, replacing text, inserting text, inserting pictures, inserting tables, inserting text at bookmarks, inserting pictures, inserting tables, etc. Fill the data into the table to read the table data, version 1.1 enhanced functions: specify text style, specify table style. In this way, word documents can be typeset dynamically.

4. Excel is ok with iText. It is also a nightmare for a large number of complex words. The usage is very simple, but there are few functions and the printing direction cannot be set.

5. The JSP output style is basically not up to standard, and it is even more terrible to print it out.

6. It's very simple to do it in XML. Word has supported the XML format since 2003. The general idea is to first edit the word style with office2003 or 2007, then save it as xml, translate the xml into a FreeMarker template, and finally use java to parse the FreeMarker template and output Doc. After testing, the word document generated in this way is in full compliance with the office standard. The style and content control is very convenient, and the printing will not be deformed. The generated document is exactly the same as the edited document in the office.


Summary of java generated pdf program:

1. Jasper Report generates pdf: The design idea is to first generate the template, then get the data, and finally integrate the two to get the result. But the problem with Jasper Report is that the way it generates templates is too complicated. Even with the help of IDE, we still need to understand many of the rules, otherwise it will bring great trouble to debugging.

2. Openoffice generates pdf: openoffice is open source software and can run on windows and linux platforms.

3. Itext + flying saucer generates pdf: itext and flying saucer are both free and open source, and have nothing to do with the platform, combined with css and velocity technology, can be implemented very well.

Comparison of advantages and disadvantages of JAVA generated word

Technology used

advantage

Disadvantage

Jacob

Powerful

Large amount of code, cumbersome setting of styles; requires windows platform support, not cross-platform

Apache POI

Powerful reading and writing excel function, simple operation

Generally only use it to read word, can create simple word, can not set style, too few functions

Java2word

Powerful and easy to operate

Can meet the general requirements, does not support the 07 format, developed by the Chinese, more reference materials, need windows platform support

iText

Full function, can meet general requirements

Cannot directly generate or manipulate doc documents, only rtf format documents can be generated, rtf can also be opened with word

JSP

Simple operation, less code

Can export a simple word from the current page, can not set the style, poor aesthetics, can not operate the word

XML (best)

The amount of code is small, the style and content are easy to control, the printing is not deformed, and it is fully in line with office standards

需要提前设计好word模板,把需要替换的地方用特殊标记标出来

JAVA生成pdf优缺点对比

所用技术

优点

缺点

openoffice

本身就是office软件,很容易设计一些文档模板,支持java调用实现word转换成pdf

需要先安装,设计好pdf模板样式,然后用程序来填充那些预留好的变量

itext

能满足要求,本身提供了一些api

无法识别很多html的tag和attribute,无法识别css,需要用其api函数来设置样式

Jasper Report

能满足要求,市面上使用的比较多,相关文档多

复杂,很难完全掌握,需要先设计模板,强依赖于IDE进行可视化编辑

flying sauser(最佳)

能解析html和css输出成image、pdf等格式,操作简单,api强大

需要编写freemarker或velocity模板,打造html,勾画pdf的样式

///

邪恶的分割线,以下是我处理word 的常用解决方式:

Birt报表的设计和导出word及其他格式文件:

由于通过Birt报表引擎的可以直接导出PDF,HTML,Word,Excel,PPT等格式.具体步骤:

1.设计报表的模板,这部分可以直接在Eclipse中可视化完成,生成".rptdesign"的设计模板(XML格式),事实上每套设计模板都需要实现制定数据源,最好是同    时指定相应的"XSD"文件,直接在eclipse中的可以看到各种格式的预览效果

2.通过解析xml更改 rptdesign 中描述数据源的标签<oda-data-source>

   将符合"xsd"的数据源文件的地址写入rptdesign

3.调用Birt引擎载入rptdesign,动态生成需要的格式文件,如word,pdf的没过

优势:

@只需要一套rptdesign文件,就可以生成所有格式的文件,因为所有的格式都是在第三步中动态制定的

劣势:

@文件的最后染效果是由birt实现的,当结果不满足自己的要求时,很难排查具体的原因.


利用WordprocessingML生成word

1.office word 2003 版以后的word 排版软件可以支持导出xml,从而对word的操作可以改变成为对xml的操作

2.官方http://rep.oio.dk/Microsoft.com/officeschemas/wordprocessingml_article.htm#wordprocessingml_article_section1wordprocessingmloverview

优势:

@这种形式类似于 "用freemaker导出word",但是因为对xml的操作更加灵活,你可以在代码中随意添加逻辑控制,如循环和条件判断

劣势:

@需要详细了解xml标签的内容,工作量比较大.

@最后生成的xml文件可以用microsoft office的软件打开,但是目前不支持wps和其他linux等环境下的排版软件







JAVA生成word优缺点对比

所用技术

优点

缺点

Jacob

功能强大

代码量大,设置样式繁琐;需要windows平台支持,无法跨平台

Apache POI

读写excel功能强大、操作简单

一般只用它读取word,能够创建简单的word,不能设置样式,功能太少

Java2word

功能强大,操作简单

能满足一般要求,不支持07格式,国人开发的,参考资料较多,需要windows平台支持

iText

功能全,能满足一般要求

不能直接生成或操作doc文档,只能生成rtf格式的文档,rtf也可以用word打开

JSP

操作简单,代码量少

能把当前页面导出简单的word,不能设置样式,美观性差,无法操作word

XML(最佳)

代码量少,样式、内容容易控制,打印不变形,完全符合office标准

需要提前设计好word模板,把需要替换的地方用特殊标记标出来

JAVA生成pdf优缺点对比

所用技术

优点

缺点

openoffice

本身就是office软件,很容易设计一些文档模板,支持java调用实现word转换成pdf

需要先安装,设计好pdf模板样式,然后用程序来填充那些预留好的变量

itext

能满足要求,本身提供了一些api

无法识别很多html的tag和attribute,无法识别css,需要用其api函数来设置样式

Jasper Report

能满足要求,市面上使用的比较多,相关文档多

复杂,很难完全掌握,需要先设计模板,强依赖于IDE进行可视化编辑

flying sauser(最佳)

能解析html和css输出成image、pdf等格式,操作简单,api强大

需要编写freemarker或velocity模板,打造html,勾画pdf的样式

Guess you like

Origin blog.csdn.net/lewee0215/article/details/44238889