[JAVA] I tried printing a form with Spring MVC and JasperReports Extra edition (Variables edition)

Articles up to the last time

I want to display the number of pages

If it's a form, there is a guy who is definitely at the bottom of the page. ** Number of pages **.

JasperReport has a system variable called Variables, The user can copy the numbers that the system spits out to the form. Let's do it

Show page footer

This is the form I used until the last time.

image.png

I want each page, so I will display the page footer.

Place a text field

What i want this time ** Current number of pages ** and ** Total number of pages **.

Therefore, place two text fields.

image.png

Set Variables in the text field.

Let's set Variables in the placed text field

Maybe I want a footer like this.

1/2

Let's achieve this. In Expression in the text field on the left

$V{PAGE_NUMBER} + "/"

In the text field on the right

$V{PAGE_NUMBER}

Let's set.

image.png

Don't forget to set the font

Edit jrxml.

If 5 pages are printed as it is 1/1  2/2  3/3  4/4  5/5 Will be printed.

It's natural because the same variable is specified.

To avoid this, change the settings in the text field on the right.

Please open ** Source ** of the form.

image.png

I think that such a screen came out. This xml file is the identity of the jrxml: form file.

You used to operate this with GUI tools.

Tweak the source to get the ** total number of pages **. Look for the tag on the right.

(I intentionally add xml as an extension to add color.

Blank_A4.xml


			<textField>
				<reportElement x="520" y="35" width="34" height="14" uuid="a26088d6-0466-4753-b5ba-8932673a1ecf"/>
				<textElement>
					<font fontName="IPAexg"/>
				</textElement>
				<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
			</textField>

Add attributes to the textField tag here. Please edit like this.

Blank_A4.xml


			<textField evaluationTime="Report">>
				<reportElement x="520" y="35" width="34" height="14" uuid="a26088d6-0466-4753-b5ba-8932673a1ecf"/>
				<textElement>
					<font fontName="IPAexg"/>
				</textElement>
				<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
			</textField>

This evaluationTime is an attribute that edits the evaluation timing. The default is Now, which is set to display the current number of pages. Change this to Report and change it to get the total number of pages in the report.

Run

Let's execute it after setting.

image.png

The number of pages is printed properly.

Reference

Recommended Posts

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 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 2/3 (form template creation)
I tried to implement file upload with Spring MVC
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
How to create an Excel form using a template file with Spring MVC
I tried to clone a web application full of bugs with Spring Boot
I also tried WebAssembly with Nim and C
I tried to link JavaFX and Spring Framework.
I tried to break a block with java (1)
I tried Spring.
I made a function to register images with API in Spring Framework. Part 1 (API edition)
I tried to read and output CSV with Outsystems
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 made a function to register images with API in Spring Framework. Part 2 (Client Edition)
[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