Skip to content

pdfHTML is an iText add-on for Java that allows you to easily convert HTML and CSS into standards compliant PDFs that are accessible, searchable and usable for indexing.

License

Notifications You must be signed in to change notification settings

itext/itext-pdfhtml-java

Logo iText

Maven Central AGPL License GitHub all releases GitHub commit activity (branch)

html2PDF is an iText Core add-on available for Java and C# (.NET) that allows you to easily convert HTML and CSS into standards compliant PDFs that are accessible, searchable and usable for indexing.

The key features of html2PDF are:

  • Converting XML/HTML & CSS to PDF or PDF/A
  • Convert XML/HTML & CSS to iText objects
  • Good default support for HTML5 and CSS3
  • Easily configurable and extensible when needed
  • Not based on any browser engine implementation

For the full list of supported\unsupported features please refer to Supported\Unsupported featues

Want to discover what's possible? Head over to our Demo Lab! It contains a collection of demo applications ready to use online!

Getting started

The easiest way to get started is to use Maven, just add the following entries to your pom.xml file:

<properties>
    <html2pdf.version>REPLACE_WITH_DESIRED_VERSION</html2pdf.version>
    <pdfua.version>REPLACE_WITH_DESIRED_VERSION</pdfua.version>
</properties>
<dependencies>
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>html2pdf</artifactId>
        <version>${html2pdf.version}</version>
    </dependency>
</dependencies>

For more advanced use cases, please refer to the Installation guidelines. You can also build iText Community from source.

Hello html2PDF!

The following code snippet shows how to convert HTML to PDF using the HtmlConverter class:

package com.itextpdf.hellohtml2pdf;

import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.kernel.pdf.PdfWriter;

import java.io.FileInputStream;
import java.io.IOException;

public class Html2PdfApp {

    public static void main(String[] args) throws IOException {
        //Convert from String
        HtmlConverter.convertToPdf("<h1>Hello world</h1>", new PdfWriter("./out.pdf"));
        //Convert from File
        HtmlConverter.convertToPdf(new FileInputStream("./path-to-html-file.html"),
                new PdfWriter("./out2.pdf"));
    }
}

Examples

Description Link
Convert HTML to PDF/A-3B compliant document Java, PDF
Convert HTML with custom QR code tags to PDF Java, PDF
Create accessible tagged PDF from HTML content Java, PDF
Convert HTML to PDF simulating color blindness vision Java, PDF
Register custom fonts for HTML to PDF Java
Convert HTML forms to tagged PDF with custom roles Java, PDF
Convert HTML file with assets Java, PDF
Enable formfield interactivity Java, PDF
Convert HTML containing arabic and hebrew Java, PDF

FAQs, tutorials, etc.

Check out the iText Knowledge Base for the iText Jump-start tutorial and other tutorials, FAQs and more.

Many common questions have already been answered on Stack Overflow, so make sure to also check there.

Contributing

Many people have contributed to iText Community over the years. If you've found a bug, a mistake in documentation, or have a hot new feature you want to implement, we welcome your contributions.

Small changes or fixes can be submitted as a Pull Request, while for major changes we request you contact us at community@apryse.com so we can better coordinate our efforts and prevent duplication of work.

Please read our Contribution Guidelines for details on code submissions, coding rules, and more.

Licensing

html2Pdf is dual licensed as AGPL/Commercial software.

AGPL is a free/open-source software license, however, this doesn't mean the software is gratis!

The AGPL is a copyleft license, which means that any derivative work must also be licensed under the same terms. If you’re using iText in software or a service which cannot comply with the AGPL terms, we have a commercial license available that exempts you from such obligations.

Contact Sales for more info.