【问题标题】:Making a paragraph in iText pdf not divided in two pages在 iText pdf 中制作段落不分为两页
【发布时间】:2011-10-19 00:06:10
【问题描述】:

我正在用 iText 编写一个 pdf 文件,我希望将段落分成两个不同的页面。我该怎么做?

【问题讨论】:

  • 一切皆有可能,但是;截屏?代码?

标签: java pdf itext


【解决方案1】:

如果您能提供一个更准确的段落示例和您正在创建的文档,帮助会容易得多,但据我了解,它是这样的:

生成一个 ArrayList 或其他选择的武器来制作一个可迭代的段落列表。在将内容添加到第 2 页之前,遍历该列表并调用 newPage()

 Document document = new Document();
 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream([file]));   

 for (ArrayList<Paragraph> : theParagraph ) {   
    document.addElement(theParagraph)
    document.newPage();

 }
 document.close();

这将在 pdf 文档中添加内容时自动添加新页面,但对分页符发生时间的控制较少:

Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream([file])); 
document.open();
for(int i=0 ; i<100; i++){
    document.add(new Paragraph("This is a very important message"));
}
document.close();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多