Steve Waters Steve Waters - 1 year ago 174
HTML Question

itext: Change font size of XMLWorker-parsed element

I'm adding Elements from an ElementList to a PdfPCell. These elements can be anything from simple text phrases to bulletpoint lists. However, the font with which these elements are printed to the pdf is too big size. So, my question is: How to adjust the default font size for elements which are parsed to the pdf.

I know how to do it with paragrhaps, where you can enter the string and the font as parameters, but how to do that when adding elements to the cell as follows:

PdfPCell cell = new PdfPCell();
for (Element e : XMLWorkerHelper.parseToElementList(HTML, CSS)) {
cell.addElement(e);
}
table.addCell(cell);

Answer Source

I found at least one way to do it by getting the chunks out of each element and setting the font for that chunk. ie:

Font f = new Font();
f.setSize(8);

for (Element e : XMLWorkerHelper.parseToElementList(content, null)) {
    for (Chunk c : e.getChunks()) {
        c.setFont(f);
    }
    cell.addElement(e);
}    
    table.addCell(cell); 
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download