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


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


– SpringBoot
– iText 5.0.6


Project Structure ->


Create SpringBoot project

Use SpringToolSuite to create a SpringBoot project with below dependencies:

Customer Model ->

JPA Customer Repository ->

Implement PDF Generator ->

– 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 ->

Run & Check Results

Run the SpringBoot project, results:

-> MySQL’s records:


-> PDF File:




By grokonez | October 15, 2018.

Related Posts

5 thoughts on “iText PDF + SpringBoot RestAPI – Extract MySQL Data to PDF File”

  1. 1. How can I make generated pdf file automatic download when I hit the api link(like your xls tutorial)
    2. How to make this as generic? For example I have different different objects like customer, user product and I want to make something generic to prepare pdf, xls and download?

    1. Hello, what you have to do is change only ine line of code, this change will let you open de pdf in one separated page and download de pdf:

      headers.add(“Content-Disposition”, “attachment; filename=customers.pdf”);

  2. Hi, Thank for this post. But i have somme difficulties to use this service by my restful (RestTemplate is my client template) ?

  3. Thank you for your post. I encountered by this error:
    “status”:500,”error”:”Internal Server Error”,”trace”:”org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class net.sf.jasperreports.repo.InputStreamResource] with preset Content-Type ‘application/pdf’.
    Please advice

Got Something To Say:

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