1

We are using itextpdf for creating PDFs. We have one cell whose values are in HTML format. We need to convert those HTML values to text.

Is it possible to convert only one PDF cell using XMLWorker?

mkl
  • 90,588
  • 15
  • 125
  • 265

1 Answers1

1

You can create your own elementHandler and use that to process a simple HTML line. The HTML String in my sample below is the following:

private static final String HTML = "<b>Test XmlWorker</b>";

And my code sample:

XMLWorkerHelper.getInstance().parseXHtml(new ElementHandler() {
    @Override
    public void add(Writable writable) {
        // process your element here
    }
}, new StringReader(HTML));

In the body of the ElementHandler.add(Writable) method you can add the element parsed from the HTML to a list or add it directly to a Document object or whatever you want to do with it.

Michaël Demey
  • 1,567
  • 10
  • 18
  • When I try to do this, I receive following error `java.lang.NoSuchMethodError: com.itextpdf.tool.xml.html.pdfelement.NoNewLineParagraph.setMultipliedLeading(F)V`... It seems the `` tag is not working for me and I have no idea why :) I made a question about it: http://stackoverflow.com/questions/23390011/itext-xmlworker-with-javafx-htmleditor – Perneel May 05 '14 at 09:28