I tried printing a form with Spring MVC and JasperReports 2/3 (form template creation)

Previous article

Create a form template.

Reference https://amg-solution.jp/blog/1519

Until JasperReport outputs PDF

JasperReport converts the form to PDF according to the following flow.

Load the form template ↓ Compile template ↓ Embed data in template ↓ Output as PDF file

So let's first create a template file that will be the type

Make a form template.

First, create a folder called report under resource (any name is fine) and right-click! Click ** New ** to ** JasperReports **

image.png

Use the Blank_A4 template. Click Blank A4 to Next, enter the file name to Next

Click ** One Empty Record ** for ** Data Adapter ** to continue. JasperReport has a function to bring data directly from DB. But most of the time, you want to process it in Java and use it. So set it empty.

image.png

When ** Congratulations ** is displayed, the wizard is complete!

Grasp "Band"

I think that such a screen came out.

image.png

This is the composition of the page called a band. The title is at the top of the page, and the page header and page footer are always printed at the beginning and end of the page. The text is output in Detail 1.

Take over the tutorial here and remove the extra bands.

Right-click ** Page_Header ** from ** Outline ** and select ** delete **.

Place fixed characters on the screen

The basic usage of JasperReport is easy.

Let's drag Static Text on the right side of the screen to the screen.

image.png

You now have a fixed text. I will display the Japanese of this.

Click the text to see the ** Property View **. From this property, you can manipulate this element (called). Open the StaticText tab in the properties and change ** Text **. If you change it, change it to Japanese font ** Change Font ** to IPAexg

image.png

Next, let's enter the date and customer name.

Place "dynamic characters" (parameters) on the screen

Next I would like to enter the date and customer name. The date and customer name change each time you print, so you need to control it from Java. JasperReport provides a container called parameters to receive values from Java. Let's make it right away.

Create a parameter

Let's open ** Parameters ** from ** Outline ** image.png

The list in the right frame is the default parameter that the template has. This time, I want to prepare a new customer name and date, so let's prepare parameters ** Client_name ** and ** Date_today **.

Right-click Parameters and click ** create Parameter **.

Change Name to ** Client_name ** and press Ctrl + s. You can leave the type as String. Let's make ** Date_today ** in the same way.

Place a Text Field

Now the form is ready to assign a value. However, the process of drawing this has not been completed. Place ** Text Filed ** on the screen and draw the parameter values.

Drag two ** TextField ** onto the screen

Once placed, one will be the customer name and the other the date. Open the TextField properties and open the TextField tab.

Associate this ** Expression ** with a parameter. Change the customer name to ** $ P {Client_name} ** and the date to ** $ P {Date_today} **. Like this (Although I will omit it from here, please ** change all fonts to IPAexg ** for the elements placed on the screen.)

image.png

Is it like this?

Place a table on the screen

Then the main form. Make a table.

this time

Column 1: Product Name (String) Column 2: Price (Integer)

Make a very simple table.

Right-click ** Field ** in the outline and click ** create Field **

Create fields for ** product_name ** (String type) and ** price ** (Integer type).

image.png

If you can, select this and drag it to the template!

image.png

(Of course, the created field also changes the font.)

Let's change the format of the numbers and make it cool. You can select the format from the ** TextField ** Pattern. It is the same as Excel and Java formats, so let's make it with reference to that.

image.png

Now you have the necessary elements for the sample form. Let's make it look a little better.

image.png

It turned out to be something like this. (You can color the border by clicking the qualification from the Borders tab.)

When it comes to a real business document, I think that the opening greetings and closing words will be included, but this time I have omitted it for the sake of clarity.

This completes the form template. After that, let's write the processing on the Java side that controls this

bonus.

You can also preview the created form. Let's switch the tab at the bottom of the form screen from ** Design ** to ** preview ** (if you get a compile error, the file should be buggy at the time of the form)

The setting to enter the value in the parameter is displayed, so let's brew and preview the value you like

image.png

Continued next time

Recommended Posts

I tried printing a form with Spring MVC and JasperReports 2/3 (form template creation)
I tried printing a form with Spring MVC and JasperReports 1/3 (JasperReports settings)
I tried printing a form with Spring MVC and JasperReports 3/3 (Spring MVC control)
I tried printing a form with Spring MVC and JasperReports Extra edition (Variables edition)
I tried printing a form with Spring MVC and JasperReports Extra edition (image edition)
I tried connecting to MySQL using JDBC Template with Spring MVC
How to create an Excel form using a template file with Spring MVC
I tried to implement file upload with Spring MVC
I tried to create a shopping site administrator function / screen with Java and Spring
I tried GraphQL with Spring Boot
I tried Flyway with Spring Boot
I tried to create a Spring MVC development environment on Mac
I made a simple search form with Spring Boot + GitHub Search API.
I tried playing with BottomNavigationView a little ①
I tried Lazy Initialization with Spring Boot 2.2.0
Spring5 MVC Web application development with Visual Studio Code Maven template creation
Just input and output images with Spring MVC
I also tried WebAssembly with Nim and C
I tried Spring.
I tried to link JavaFX and Spring Framework.
I tried to clone a web application full of bugs with Spring Boot
Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world
I tried to break a block with java (1)
Spring Security usage memo: Cooperation with Spring MVC and Boot
I started MySQL 5.7 with docker-compose and tried to connect
[Ruby] I made a crawler with anemone and nokogiri.
I tried to get started with Spring Data JPA
I made a Restful server and client in Spring.
I tried OCR processing a PDF file with Java
I wrote a test with Spring Boot + JUnit 5 now
[I tried] Spring tutorial
I tried Spring Batch
I tried to create a java8 development environment with Chocolatey
I tried to modernize a Java EE application with OpenShift.
[Rails] I tried to create a mini app with FullCalendar
Spring Boot Introductory Guide I tried [Accessing Data with JPA]
I tried to verify this and that of Spring @ Transactional
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
I tried JAX-RS and made a note of the procedure
I tried to create a padrino development environment with Docker
I tried OCR processing a PDF file with Java part2
I tried to get started with Swagger using Spring Boot
I made a simple MVC sample system using Spring Boot
I tried to express the result of before and after of Date class with a number line
Java Config with Spring MVC
I tried DI with Ruby
I tried Spring State machine
I tried UPSERT with PostgreSQL.
I tried BIND with Docker
I tried Spring Boot introductory guide [Building a RESTful Web Service]
I tried running a letter of credit transaction application with Corda 1
Create a parent-child relationship form with form_object (I also wrote a test)
I tried to make an Android application with MVC now (Java)
I tried deploying a Docker container on Lambda with Serverless Framework
Spring Boot Introductory Guide I tried [Consuming a RESTful Web Service]
I tried to make a group function (bulletin board) with Rails
I tried to make a machine learning application with Dash (+ Docker) part1 ~ Environment construction and operation check ~