在Android底部的iText库底部动态添加段落

时间:2015-03-23 11:51:55

标签: android itext

我正在使用下面的代码,但这不能正常显示底部的一行,而我想在每个页面的底部都有一个段落。

public void onEndPage(PdfWriter writer, Document document) {
          Rectangle rect = writer.getBoxSize("art");
          ColumnText.showTextAligned(writer.getDirectContent(),
                  Element.ALIGN_LEFT, new Phrase(ActivityWaTestamentInput.pDFHeaderText,headerFont),
                  rect.getLeft(), rect.getTop(), 0);
          ColumnText.showTextAligned(writer.getDirectContent(),
                  Element.ALIGN_LEFT, new Paragraph(ActivityWaTestamentInput.pDFFooterText,footerFont),
                  rect.getLeft() , rect.getBottom() - 18, 0); 

1 个答案:

答案 0 :(得分:0)

如记录所示,ColumnText.showTextAligned()只会显示一行。如果您需要多行,那么您也可以使用ColumnText,但您需要以不同的方式使用它。

请下载免费的电子书The Best iText Questions on StackOverflow。在文本"的绝对定位部分中,您将找到几个涉及ColumnText的示例。

这些是您应该检查的一些问题和答案:

这是这些问题的答案之一的代码段:

ColumnText ct = new ColumnText(cb);
ct.setSimpleColumn(120f, 500f, 250f, 780f);
Paragraph p = new Paragraph("This is a long paragraph that doesn't"
    + "fit the width we defined for the simple column of the" 
    + "ColumnText object, so it will be distributed over several"
    + "lines (and we don't know in advance how many).");
ct.addElement(p);
ct.go();

我硬编了这个位置:

llx = 120;
lly = 500;
urx = 250;
ury = 780;

这是一个左下角(120,500),宽度为130,高度为380的矩形。如果希望文本显示在页面底部,则需要调整这些值。