Source:
writer = PdfWriter.getInstance(document, new FileOutputStream("D://MetaData.pdf"));
document.open();
StringBuffer sb = new StringBuffer(text);
XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream("D:\\work\\iTextPDF\\sample1.html"));
PdfContentByte pcb = writer.getDirectContent();
ColumnText ct = new ColumnText(pcb);
ct.setAlignment(Element.ALIGN_JUSTIFIED);
ct.setText(new Phrase(sb.toString()));
float[] left = { 36, (PageSize.A4.getWidth() / 2) + 18 };
float[] right = { (PageSize.A4.getWidth() / 2) - 18, PageSize.A4.getWidth() - 36 };
int status = ColumnText.NO_MORE_COLUMN;
int column = 0;
while (ColumnText.hasMoreText(status)) {
ct.setSimpleColumn(left[column], 36, right[column], PageSize.A4.getHeight() - 36);
status = ct.go();
column++;
if (column > 1) {
column = 0;
document.newPage();
}
}
in my source code i am using XMLWorkerHelper
and ColumnText
but XMLWorkerHelper
parse the data and write into document but i want parse the data from html and set to the ColumnText
after build the document. please help me thank you in advance.