Normally we print HTML content using the following code:
PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);
XMLWorker worker = new XMLWorker(css, true);
XMLParser p = new XMLParser(worker);
p.parse(new ByteArrayInputStream(string.getBytes()));
p.flush();
worker.close();
But this doesn't handle nested lists properly. Only the first level is printed with bullets and all others simply follow inline... without any breaks.
I've tried to adapt https://stackoverflow.com/a/26757887/173689... with iText v5.5.8.
ElementHandlerPipeline end = new ElementHandlerPipeline(new ElementList(), null);
HtmlPipeline html = new HtmlPipeline(htmlContext, end);
CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);
XMLWorker worker = new XMLWorker(css, true);
XMLParser p = new XMLParser(worker);
p.parse(new ByteArrayInputStream(string.getBytes()));
p.flush();
worker.close();
for (Element e : elements) {
document.add(e);
}
But lists still are not nested – the result is the same. What's wrong?