JavaFx html formatted text in pdf using iText with formatation

419 views Asked by At

Is it possible to set a formatted HTML-Text (Color, Alignment, ...) from a HTMLEditor to an "editable" PDF using iText.

I didn't find anything on the internet.

Thanks.

2

There are 2 answers

0
Joris Schellekens On BEST ANSWER

The easiest way of doing this is (as Amedee suggested) using pdfHTML. It's an iText7 add-on that converts HTML5 (+CSS3) into pdf syntax.

The code is pretty straightforward:

    HtmlConverter.convertToPdf(
        "<b>This text should be written in bold.</b>", // html to be converted
        new PdfWriter(
            new File("C://users/user2002/output.pdf")  // destination file
        )
    );

To learn more, go to https://itextpdf.com/itext7/pdfHTML

0
AudioBubble On

I found a Solution in this post using The Flying Saucer: this