Search code examples
javahtmljavafxitexthtml-editor

JavaFx html formatted text in pdf using iText with formatation


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.


Solution

  • 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