Pravin R. Joshi
Pravin R. Joshi

Reputation: 11

Create PDF from html page using spring boot

I have project based on spring boot. which create salary slip for employee dynamically, now i want to convert that salary slip which is html page to PDF and push it to my server folder. i have done this with JQuery.

My question is:

1] can i push PDF created by JQuery on server?
2] Or any java library to convert that html to PDF?

Upvotes: 0

Views: 2911

Answers (2)

Deep Sodhi
Deep Sodhi

Reputation: 211

You can use Java Library Flying Saucer for this. In your spring based project add the following dependencies in your pom.xml

<dependency>
    <groupId>org.xhtmlrenderer</groupId>
    <artifactId>flying-saucer-pdf</artifactId>
    <version>9.1.13</version>
</dependency>

Upload the html file through POST and use this library's functions to convert in into pdf

You can read about Flying Saucer here

Upvotes: 1

khoibv
khoibv

Reputation: 369

  1. You can use $.ajax to upload

JS:

var form_data = new FormData();
form_data.append('file', pdfFile);
$.ajax({
  url: path/to/upload
  data: form_data,
  processData: false
})

Java:

public void uploadPdf(@RequestParam(name = "file") MultipartFile pdfFile)
  1. You can try wkhtmltopdf (https://wkhtmltopdf.org/)

Upvotes: 0

Related Questions