Method (parseToElementList(str,null)) not found in XMLWorkerHelper class for Itext

1.3k Views Asked by At

I am new in iText, I want to convert HTML string to Pdf in Itext. I found lots of example on the Internet. Then I found one example and want to implement same here, but not able to implement the example in my project. I added dependencies in my pom.XML file .

Here is the link :

https://developers.itextpdf.com/examples/xml-worker-itext5/basic-html-examples

Pom.xml

<!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itextpdf</artifactId>
        <version>5.0.6</version>
    </dependency>
**<!-- https://mvnrepository.com/artifact/com.itextpdf.tool/xmlworker -->
<dependency>
    <groupId>com.itextpdf.tool</groupId>
    <artifactId>xmlworker</artifactId>
    <version>5.4.1</version>
</dependency>**

Code snippet:

                PdfPTable table = new PdfPTable(1);
                PdfPCell cell = new PdfPCell();
                ElementList list =XMLWorkerHelper.parseToElementList(encountersoapnotes.getHpi(), null);
                for (Element element : list) {
                    cell.addElement(element);
                }
                table.addCell(cell);
                document.add(table);

The above parseToElementList(str,null) method is not available after installing maven command.

Anyone give me the maven dependency for this XMLWorkerHelper class which contains parseToElementList(str,null) method.

enter image description here

Thanks Sitansu

1

There are 1 best solutions below

0
Amedee Van Gasse On

If you are new to iText, then you should not start with such an old version. You should start with the current version: iText 7.1.1 + pdfHTML 2.0.1. With that version, you need as little code as this:

public static void main() throws IOException {
   // IO File htmlSource = new File("input.html");
   File pdfDest = new File("output.pdf");
   // pdfHTML specific code
   ConverterProperties converterProperties = new ConverterProperties();
   HtmlConverter.convertToPdf(new FileInputStream(htmlSource), new FileOutputStream(pdfDest), converterProperties);
}

More information, tutorials, downloads etc at https://itextpdf.com/itext7/pdfHTML