Ireport and jasperreport integrated Web report development wizard (2)

Source: Internet
Author: User

In the previous document, we initially introduced ireport and jasperreport. Basically, we have an initial understanding of them. In this document, I will provide an in-depth description of the ireport tool.

At the end of the previous document, if we successfully run ireport, we can see the following main interface:

Click "add" to create a new empty report. The generated XML file can be edited to display Chinese characters, please add gb2312 on the XML encoding option (you do not have the option to manually enter it), for example:

After the necessary options are set, click Finish to get a blank report, for example:

All right, enter a piece of text. It is very easy. Click the "Create static text" button and enter it in any Workspace of the report (such as title, pageheader, detail, pagefooter summary, and so on, for example, enter "today's weather is good! ". On the attribute box page, you can control the attributes of the input content, such as the font, color, size, and other attributes, and any elements in the report (static text, line, box, and so on) each element has its own property page. You can double-click any element to pop up the property page of this element. The property page is as follows:

After completion, a simple report is generated. The ireport is equipped with a running environment. The following shortcut is provided:

The button on the left is to run the static report (without the database environment), and the button on the right is to run the dynamic report (in this case, you need to set the database connection. The connection of the database is described below)

After the above efforts, it is clear that we are going to run the static report, then click the button on the left to see the following PDF,

Of course, the previous example is the simplest.

I will use the Q & A method to explain the ireport usage step by step.
1. How to connect to the database?
2. How to define variables, parameters, and fields?
3. How to define fonts and how to use custom fonts (such as simhei, simhei, or more artistic child )?
4. How to execute an SQL script for query?
5. How to introduce prepared reports to applicationsProgramMedium?

Well, I will answer the above questions in the following sections and introduce other functional menus in ireport.

1. How to connect to the database?

In fact, there are very few static reports. I mentioned a classic term in the previous article: "A datasource + A Jasper = a print". Therefore, it is necessary to first introduce how to connect to the database, it is actually very simple. Go to the datasource/connections/CES menu or click the shortcut button. The following property page is displayed:

Configure necessary database connection properties, and click the test button for testing. If the test is successful, save the database connection.

2. How to define variables, parameters, and fields?

Variables, parameters, and field definitions are convenient in ireport. Some control points can be seen in the menu view, such:

Set Report Properties

REPORT query sets the query statement, which is described below

Report fields field (database)

Report variables setting Variables

Report parameters setting parameters

Report fonts font setting

By the way, you can also describe the following:

Bands. The properties page of the report workspace (such as title detail) is displayed.

Report groups setting group

Element properties element property page

Element browser displays a list of all elements in the report.

It is easy to set, but when you reference these variables, parameters, and fields in a report, you can write a statement.
The reference method in ireport is as follows:

Element Name Reference
Variable Variablesname $ V {variablesname}
Parameters Parametername $ P {parametername}
Field Filedsname $ F {filedsname}

In fact, these do not seem to know how to do it, a single explanation, they are also very useful and very simple. More!

3. How to define fonts and how to use custom fonts (such as simhei, simhei, or more artistic child )?

Because the Asian Font is used, you need to download the additional ja R package itextasian. Jar. If the ireport package contains this jar package, this step is free of charge.

Currently, ireport only has one Chinese font. If you want to use other fonts (such as and ), you need to use another method, which is described below, the following describes how to use the frequently-used Chinese font "". In question 2, we can see the option to introduce the font. Click "report fonts" to see the following property page:

Well, as shown in the preceding settings, has been set. This font can be referenced anywhere in the report in the future, for example, let's take the element in the above example as follows: "Today's weather is good!" Change to, as shown below:

So long as we select songti in the report font option, the following attributes will be automatically inherited!
Well, the following describes how to use Chinese fonts other than, such as,, or other artistic fonts.

It is also very simple, but it seems that the current ireport function is not perfect, but you need to manually modify the XML file to meet the requirements, as we define the:

The first difference is that select External TTF font… in the PDF Font Name option ..., In common sense, select the simhei TTF file in the following options. TTF, but I don't know why the option of TrueType font is empty. (This step made me feel better when I was studying.) Oh, my God, what should I do ?!

Later, I checked the corresponding XML file, as shown below: (because the file is large, only what we care about is intercepted)

 

<Statictext>
<Reportelement
Mode = "Opaque"
X = "13"
Y = "42"
Width = "239"
Height = "53"
Forecolor = "#000000"
Backcolor = "# ffffff"
Positiontype = "fixrelativetotop"
Isprintrepeatedvalues = "true"
Isremovelinewhenblank = "false"
Isprintinfirstwholeband = "false"
Isprintwhenderson etailoverflows = "false"/>
<Textelement textalignment = "Left" verticalalignment = "TOP" linespacing = "single">
<Font fontname = "" pdffontname = "" size = "36" isbold = "false" isitalic = "false" isunderline = "false" ispdfembedded = "true" pdfencoding = "Identity -h "isstrikethrough =" false "/>
</Textelement>
<Text> </text>
</Statictext>

We can see that the "pdffontname =" "In is empty, so I tried to set the TTF file path (C:/winnt/fonts/simhei. TTF) write it to this place. Haha, it was successful.

So I came to the conclusion that if you use other fonts in the report, you should first set the attributes in the figure above, and then manually write the TTF file of the font to pdffontname = "", although it is troublesome, it is quite helpful!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.