iText PDF + SpringBoot RestAPI – Extract MySQL Data to PDF File

spring-boot-spring-jpa-export-data-pdf-table-file-by-itext-mysql-feature-image

In the tutorial, we show you how to create a SpringBoot RestAPIs application that uses Spring JPA & iText library to extract data from MySQL records to a PDF file in table format.

Related posts:
How to use Spring JPA with PostgreSQL | Spring Boot

Technologies

– SpringBoot
– iText 5.0.6
– MySQL

Practice

Project Structure ->

spring-boot-spring-jpa-export-data-pdf-table-file-by-itext-mysql-project-structure

Create SpringBoot project

Use SpringToolSuite to create a SpringBoot project with below dependencies:

Customer Model

Customer.java ->

JPA Customer Repository

CustomerRepository.java ->

Implement PDF Generator

PDFGenerator.java ->

– Segment Code to add PDF text with iText:

– Segment code to create PDF table having 3 columns:

-> Create table’s headers:

-> Add table’s rows, each row has 3 cells that contains a Customer’s data: {id, firstName, lastName}:

Implement RestAPI Controller

CustomerRestAPIs ->

Initial Customers

– In main class, we use CommandLineRunner to init Customer’s records:

Database Configuration

application.properties ->

Run & Check Results

Run the SpringBoot project, results:

-> MySQL’s records:

spring-boot-spring-jpa-export-data-pdf-table-file-by-itext-mysql-records

-> PDF File:

spring-boot-spring-jpa-export-data-pdf-table-file-by-itext-mysql-results

SourceCode

SpringJpaPDFReport

By grokonez | October 15, 2018.



Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*