Radika Moonesinghe
Radika Moonesinghe

Reputation: 489

Springboot Form convert HTML - > PDF

How in a java project can a HTML form upon submission be converted to PDF and then attached to a email.

Springboot & Thymeleaf are the frameworks in use. The form looks like this:

http://jsfiddle.net/x1hphsvb/5563/

Controller so far:

@org.springframework.stereotype.Controller
@EnableAutoConfiguration
public class Controller {

@RequestMapping("/")
String home() {
    return "static/index.html";
}

public static void main(String[] args) throws Exception {
    SpringApplication.run(Controller.class, args);
    }
}

I have looked at this tutorial and searched for a way to do it with PDF Box without success.

Should I take the data in the back end and insert it into a HTML template or insert the data into a PDF template.

The PDF form should also have the collapsability similar to the HTML.

Upvotes: 0

Views: 9532

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

Regarding the conversion of HTML to PDF

The example you refer to has my name in it (a reference to a package name starting with com.lowagie) which means it's about iText, not about pdfBox. PdfBox doesn't convert HTML to PDF, so that's not an option.

Versions of iText with my name in it, predate iText 5 and should no longer be used in a commercial context. See Can iText 2.1.7 / iTextSharp 4.1.6 or earlier be used commercially?

You also use the tag Flying Saucer. Flying Saucer is a third-party tool to convert HTML to PDF that was built on top of such an old version of iText.

Tips:

Regarding PDF forms

You wrote: "The PDF form should also have the collapsability similar to the HTML."

Please check ISO 32000-2 (the PDF 2.0 standard) and you'll discover that PDF forms can't collapse the same way HTML forms collapse. You may have seen PDF documents with similar functionality, but those forms weren't ISO 32000-2 documents; they were XFA forms. XFA stands for the XML Forms Architecture, and that technology was deprecated. You'll hardly find any viewers other than Adobe Reader that support such forms.

When it comes to data entry, PDF has lost and HTML 5 has won. If you've read the answer to the question How to create template and generate pdf using template and database data iText C#, you've noticed that the DITO product chose to create HTML 5 templates for data entry and PDF templates for data presentation.

Upvotes: 1

Related Questions