iText pdfHTML was released as a replacement for XmlWorker . The C # version can be downloaded from the NuGet Gallery . The Java version can be downloaded from Artifactory .
The main class you are looking for is HtmlConverter . It has many static method overloads for converting html either a list of elements that will be added to future structures of the layout structure, a full copy of com.itextpdf.layout.Document or to the right into a .pdf file.
Example of converting a .html file to .pdf :
HtmlConverter.convertToPdf(new File(htmlFilePath), new File(outPdfFilePath));
An example of converting html to layout elements:
String html = "<p>Hello world!</p>"; List<IElement> lst = HtmlConverter.convertToElements(html);
In addition, pdfHTML now supports @media rules, so you can specify the configuration that will be used to apply CSS, for example, to use @media print instructions, you need to configure MediaDeviceDescription accordingly
ConverterProperties properties = new ConverterProperties() .setMediaDeviceDescription(new MediaDeviceDescription(MediaType.PRINT)); HtmlConverter.convertToPdf(new File(htmlPath), new File(outPdfPath), properties);
To specify the font set that you would like to use when converting HTML to PDF, you can also configure FontProvider :
FontProvider fontProvider = new FontProvider(); fontProvider.addDirectory(fontsDir) properties.setFontProvider(fontProvider);
Or you can use DefaultFontProvider and specify its settings in the constructor:
FontProvider fontProvider = new DefaultFontProvider(false, false, true); properties.setFontProvider(fontProvider);
DefaultFontProvider has three parameters in the constructor: first you need to specify whether to use standard fonts ( Helvetica , Courier , Times , etc.), the second to indicate whether to use fonts that are sent with pdfHTML , and the third to indicate whether to load system fonts. DefaultFontProvider is simply a subclass of FontProvider , so you can always call addDirectory or addFont after creating the instance.