iText PDF + Kotlin SpringBoot RestAPI + MySQL

kotlin-springboot-restapi-download-pdf-file-spring-jpa-mysql-itextpdf-feature-image

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

Related posts:
How to use Spring JPA MySQL | Spring Boot

Technologies

– Kotlin
– SpringBoot
– iText 5.0.6
– MySQL

Practice

Project Structure ->

kotlin-springboot-restapi-download-pdf-file-spring-jpa-mysql-itextpdf-project-structure

Create Kotlin SpringBoot project

Use SpringToolSuite to create a Kotlin SpringBoot project with below dependencies:

Customer Model

Customer.kt ->

JPA Customer Repository

CustomerRepository.kt ->

Implement PDF Generator

PDFGenerator.kt ->

The segment code to add PDF text with iText ->

The 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.kt ->

Implement Download View

– Create ViewController.kt ->

– Create .html view home.html ->

Initial Customers

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

Database Configuration

application.properties ->

Run & Check Results

Run the SpringBoot project,

-> MySQL’s records:

kotlin-springboot-restapi-download-pdf-file-spring-jpa-mysql-schema-records

-> PDF Downloaded File:

kotlin-springboot-restapi-download-pdf-file-spring-jpa-mysql-itextpdf-view

kotlin-springboot-restapi-download-pdf-file-spring-jpa-mysql-itextpdf-request-log

kotlin-springboot-restapi-download-pdf-file-spring-jpa-mysql-itextpdf-pdf-file (2)

SourceCode

KotlinSpringJpaPdfReport



By grokonez | October 23, 2018.


Related Posts


Got Something To Say:

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

*