It's the topic connected with List items in table cell are not formatted. I'm using XmlWorker to process HTML output from formattable control (dijit/Editor from Dojo). There are some blocks (when you use centering or margin formatters) like that:
<div>
<p align="center"><font size="5"><b> <font color="#32cd32">My centered Para</font></b></font><font color="#32cd32"> </font></p>
</div>
However, when I add them to the Paragraph
that is added to the Table like here:
PdfPCell htmlCell = new PdfPCell();
htmlCell.setBackgroundColor(new BaseColor(213, 226, 187));
htmlCell.addElement(html2Para(html));
htmlCell.setPaddingBottom(5);
htmlCell.setPaddingLeft(5);
table.addCell(htmlCell);
private Paragraph html2para(String html) {
final Paragraph para = new Paragraph();
try {
XMLWorkerHelper.getInstance().parseXHtml(new ElementHandler() {
@Override
public void add(Writable wri) {
if (wri instanceof WritableElement) {
List<Element> elems = ((WritableElement) wri).elements();
for (Element elem : elems) {
para.add(elem);
}
}
}
}, new StringReader(StringUtils.trimToEmpty(html)));
} catch (IOException e) {
log.error(e.getMessage(), e);
}
return para;
}
Everything that is inside the Element
that is the instance of PdfDiv
is not visible.
So, when I meet the PdfDiv, I add its content:
private void addElem2para(Element elem, Paragraph target) {
if (elem instanceof PdfDiv) {
for (Element inside : ((PdfDiv)elem).getContent()) {
addElem2para(inside, target);
}
} else {
target.add(elem);
}
}
However, now that formatting like centering or margin that were the properties of the PdfDiv
are 'lost'.
How should one deal with the PdfDiv
elements from XmlWorker?
I'm using iText and XmlWorker in version 5.5.2