【发布时间】:2014-03-04 13:35:07
【问题描述】:
当Element 因setKeepTogether(true) 配置而被移动到新页面时,我需要在新页面上输入“Continuation of ...”。
I tried that 与PageEvent.onStartPage(),但不允许在PageEvent 内调用Document.add()。
但是现在如何解决呢?
这个小例子重现了我的问题:
public class Main {
public static String continuation = null;
public static void main(final String[] args) throws Exception {
final Document document = new Document(PageSize.A7);
final PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("text.pdf"));
document.open();
// Now I add the introduction text
document.add(new Paragraph("A nice \nIntroduction \nover some lines."));
// Now I put my "huge" paragraph. When it breaks,
// the first line of the new page should be "Continuation of smth."
continuation = "smth.";
final Paragraph paragraph = new Paragraph("What is \nthe answer \nto life the \nuniverse and \neverything?\n\nThe Answer to \nthis question \nis:\n42");
paragraph.setKeepTogether(true);
document.add(paragraph);
document.close();
}
}
结果应该看起来像this。
【问题讨论】: