添加段落动态地与Android的iText库底 [英] Add paragraph dynamically at the bottom with iText library in android
问题描述
我使用低于code,但同时我想在底部的每一页的段落这是行不通的展现在底部只有一行。
公共无效的OnEndPage(PdfWriter作家,文档文件){
矩形RECT = writer.getBoxSize(艺术);
ColumnText.showTextAligned(writer.getDirectContent(),
Element.ALIGN_LEFT,新词(ActivityWaTestamentInput.pDFHeaderText,headerFont)
rect.getLeft(),rect.getTop(),0);
ColumnText.showTextAligned(writer.getDirectContent(),
Element.ALIGN_LEFT,新的第(ActivityWaTestamentInput.pDFFooterText,footerFont)
rect.getLeft(),rect.getBottom() - 18,0);
由于记载, ColumnText.showTextAligned()
将只显示一行。如果你需要多行,那么你也可以使用 ColumnText
,但你需要以不同的方式来使用它。
请下载免费的电子书在计算器上最佳iText的问题。在一节的文字绝对定位,你会发现,涉及 ColumnText
几个例子。
这些都是一些问题和答案,你应该检查:
- 如何适应矩形内的字符串?
- 如何画周围多行文本 <矩形/ LI>
- 内ColumnText短语iText的位置
这是其中一个答案对这些问题的一个code片断:
ColumnText克拉=新ColumnText(CB);
ct.setSimpleColumn(120F,500F,250F,780f);
第P =新的段落(这是长款,这并不
+适合我们为简单的列中定义的宽度
+ColumnText对象,所以它会在几个分布
+线(我们事先不知道多少)。);
ct.addElement(P);
ct.go();
我很难codeD的位置:
LLX = 120;
LLY = 500;
URX = 250;
URY = 780;
这是与左下角(120,500),130的宽度和380的高度你需要,如果你想要的文字出现在页面的底部,以适应这些值的矩形。
I am using below code but this is not working its show only one line in bottom while I want a paragraph in bottom in every page.
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);
As documented, ColumnText.showTextAligned()
will only show one line. If you need multiple lines, then you can also use ColumnText
, but you need to use it in a different way.
Please download the free ebook The Best iText Questions on StackOverflow. In the section "Absolute positioning of text", you'll find several examples that involve ColumnText
.
These are some questions and answers you should check:
- How to fit a String inside a rectangle?
- How to draw a rectangle around multiline text
- iText placement of Phrase within ColumnText
This is a code snippet from one of the answers to these questions:
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();
I hardcoded the position:
llx = 120;
lly = 500;
urx = 250;
ury = 780;
This is a rectangle with lower left corner (120, 500), a width of 130 and a height of 380. You will need to adapt these values if you want the text to appear at the bottom of the page.
这篇关于添加段落动态地与Android的iText库底的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!