通常我们使用以下代码打印HTML内容:
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();
但是这不能正确处理嵌套列表。只有第一级打印有子弹,而其他所有级别都只是按照内联方式...没有任何中断。
我尝试使用iText v5.5.8调整https://stackoverflow.com/a/26757887/173689 ...
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);
}
但是列表仍然没有嵌套 - 结果是一样的。怎么了?