使用iTextPDF使用XMLWorkerHelper从HTML解析数据这是直接将内容写入Document但我想使用ColumnText设置数据

时间:2016-08-25 10:24:43

标签: itext

  

来源:

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();
                }
            }

在我的源代码中我正在使用XMLWorkerHelperColumnText,但是XMLWorkerHelper解析数据并写入文档,但我想从html解析数据并设置为{{1}构建文档后。请提前帮助我谢谢

0 个答案:

没有答案