
检查下有没有documentnewPage()使得把数据放到下一页了。
如果没有,那就需要分析代码。但是换种思路也能解决你问题:
把数据作为附件一,附件二等形式生成在pdf的最后,那样就没人关注pdf内容的空白了。
用iText生成PDF文档需要5个步骤:
①建立comlowagietextDocument对象的实例。
Document document = new Document();
②建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中。
PDFWritergetInstance(document, new FileOutputStream("HelloworldPDF"));
③打开文档。
documentopen();
④向文档中添加内容。
documentadd(new Paragraph("Hello World"));
⑤关闭文档。
documentclose();
通过上面的5个步骤,就能产生一个HelloworldPDF的文件,文件内容为"Hello World"。
建立comlowagietextDocument对象的实例
comlowagietextDocument对象的构建函数有三个,分别是:
public Document();
public Document(Rectangle pageSize);
public Document(Rectangle pageSize,
int marginLeft,
int marginRight,
int marginTop,
int marginBottom);
以上就是关于如何运用Java组件itext生成pdf全部的内容,包括:如何运用Java组件itext生成pdf、java中怎么利用poi和itext生成pdf文档、itext中newpage之后添加pdfptable对象里面加不了数据等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)