简体   繁体   English

如何使用iText一个接一个添加两个段落

[英]how to add two paragraphs using iText one next to other

I want to create a PDF document using iText and in that I want to add a paragraph next to another paragraph (Left and Right). 我想使用iText创建一个PDF文档,在那我想在另一个段落(左和右)旁边添加一个段落。 I tried to merge two paragraphs by adding those two to another paragraph. 我试图通过将两个段落添加到另一个段落来合并两个段落。 But it didn't work for me. 但这对我没有用。 Please help. 请帮忙。

Thanks. 谢谢。

Perhaps it's possible to use a table? 也许可以使用表格? This example gives a 5 column table 本示例给出了一个5列表

PdfPTable t = new PdfPTable(5);

int headerwidths[] = {12, 22, 22, 22, 22};
try {
    t.setWidths(headerwidths);
} catch (Exception e) {
    System.out.println(e.getMessage());
}

t.setWidthPercentage(100);

t.addCell(borderlessCell("text", Element.ALIGN_LEFT, fBold));
t.addCell(borderlessCell("text", Element.ALIGN_CENTER, fBold));
t.addCell(borderlessCell("text", Element.ALIGN_CENTER, fBold));
t.addCell(borderlessCell("text", Element.ALIGN_CENTER, fBold));
t.addCell(borderlessCell("text", Element.ALIGN_CENTER, fBold));

you can use chunk to do this task. 您可以使用块来完成此任务。 like 喜欢

chunk c = new chunk("this is first paragraph",font);
chunk c1 = new chunk("this is second paragraph",font2);

paragraph p1 = new paragraph;

p1.add(new chunk(c1));
p1.add(new chunk(c2));

documnet.add(p1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM