我設法讓它工作。但是與表。在這種方式中的Base64圖像顯示在PDF文檔
//CSS
CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(true);
// HTML
TagProcessorFactory htmlTagProcessorFactory = Tags.getHtmlTagProcessorFactory();
//htmlTagProcessorFactory.removeProcessor(HTML.Tag.IMG);
//htmlTagProcessorFactory.addProcessor(new ImageTagProcessor(), HTML.Tag.IMG);
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
htmlContext.setTagFactory(htmlTagProcessorFactory);
htmlContext.setImageProvider(new Base64ImageProvider());
// Pipelines
ElementList elements = new ElementList();
ElementHandlerPipeline end = new ElementHandlerPipeline(elements, (Pipeline) null);
HtmlPipeline htmlPipeline = new HtmlPipeline(htmlContext, end);
CssResolverPipeline css = new CssResolverPipeline(cssResolver, htmlPipeline);
// XML Worker
XMLWorker worker = new XMLWorker(css, true);
XMLParser p = new XMLParser(worker);
p.parse(new ByteArrayInputStream(html.getBytes()));
PdfPTable table = new PdfPTable(1);
PdfPCell cell = new PdfPCell();
cell.setPadding(0);
cell.setUseBorderPadding(false);
cell.setBorder(0);
for (Element e : elements) {
cell.addElement(e);
}
table.addCell(cell);
// Adding a table at an absolute position
table.writeSelectedRows(0, -1, x, y, writer.getDirectContent());