Xmlworker is missing in iText 7 core

I am trying to use iText 7 in Java. Want to hide HTML / XHTML in PDF.

Apparently xmlworker.jar does not exist in iText 7 core .

What is iText 7 replacement?

Any solutions?

+5
source share
2 answers

XML Worker is the next thing on the roadmap in iText, so yes, it will be available for iText 7. But first we need to finish the iText 7 port for Java to iText 7 for C #, and we are still hardworking to document IText 7. See For example: IText 7 :. Building blocks

In open source, one of them is often published; one of them will be released soon. Instead of keeping all the code closed until everything is finished, we chose the open source release method: everything is ready, freed. Everything that is not ready will be released as soon as it is ready.

When overhauling iText, you need to rewrite the XML Worker. Benefit: iText 7 was written using XML Worker. All elements marked with a key in the tutorial that I mentioned are β€œnew in iText 7,” for example. property inheritance (which allows us to use CSS much better).

After that, you will see significant improvements.

+4
source

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.

+2
source

All Articles