Java export pdf report 2: technical analysis of various requirements

In the previous blog, we saw some of the requirements in this report. In this article, we will analyze the technical difficulties and choices of the above requirements.
The following are some issues that I have considered from a technical point of view after getting the requirements:

  1. How to dynamically generate the corresponding PDF
  2. What techniques are used to generate pie charts and histograms
  3. How to dynamically insert pie charts, histograms and tables into PDF documents
  4. How to dynamically generate corresponding pictures in the place of image processing in requirements
  5. If the dots of different colors in the table are put into the table
  6. how to convert word to pdf

Let me introduce my ideas one by one:
1. How to dynamically generate the corresponding PDF.
First of all, I thought of using PDF template to generate directly, using Adobe Acrobat DC as the template. But when I was working on a project before, I found that it was not very convenient to dynamically generate table data, and I didn't have much time to study, so I gave up this method.
Then, if you have used freemarker before, consider generating a word file based on the word template, and then convert word to PDF.
After exploring the feasible form of the entire technology, I found a new open source project POI-TL on the Internet, and then found that it is much more convenient to use than freemarker, and then decisively chose to use poi-tl to generate word

2. What technology is used to generate pie charts and histograms?
This selection is relatively simple. At that time, after Baidu, I directly chose jfreechart

3. How to dynamically insert pie charts, histograms and tables into PDF documents
This thinking actually runs through the first technology selection, and it is also a very important reason for choosing poi-tl. Adding pictures and tables is especially convenience. However, I also encountered a problem later, which we will introduce in a later article

4. In the image processing part of the requirement, how to dynamically generate the corresponding image
is also a point that is tangled when doing technical analysis. Later, I thought that I could use the method of image splicing to draw green dots on the long image, and then decisively In this way, we will introduce the specific implementation in the following article

5. If the dots of different colors in the table are put into the table,
at first I thought about making pictures of small dots of several colors, and judging which color picture to use according to the rules, and then inserting it into the table, but here I encountered One problem is that the current version of poi-tl does not support inserting pictures in dynamic tables, but it has also made corresponding attempts to expand the method of table processing in poi-tl, but during the test, it was found that although the pictures were inserted, the pictures A blank line will always be generated above, causing the width of the table to widen, which is very annoying.
Then by chance, I discovered that poi itself supports the insertion of special symbols, and then decisively used the special characters that directly replaced the dot pictures with dots. The specific implementation here will also be introduced in the following article.

6. How to convert word to pdf
There are also many solutions found on the Internet: JobConverter + OpenOffice, SaveAsPDFandXPS + jacob, xdocreport, LiberOffice, etc. Finally, I chose xdocreport for several reasons: the server environment is linux, OpenOffice and jacob can only be used in the windows environment, and office needs to be installed; license; ease of use

Well, the needs and problems encountered in technology selection have been introduced. Next, we will go through the difficulties one by one to see how to achieve it.

Guess you like

Origin blog.csdn.net/wzl19870309/article/details/103434232