为什么itextpdf 在生成pdf 的时候 取表格高度为0

2025-04-24 10:02:04
推荐回答(1个)
回答1:

  检查下有没有document.newPage()使得把数据放到下一页了。
如果没有,那就需要分析代码。但是换种思路也能解决你问题:
把数据作为附件一,附件二等形式生成在pdf的最后,那样就没人关注pdf内容的空白了。
  用iText生成PDF文档需要5个步骤:
  ①建立com.lowagie.text.Document对象的实例。
  Document document = new Document();
  ②建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中。
  PDFWriter.getInstance(document, new FileOutputStream("Helloworld.PDF"));
  ③打开文档。
  document.open();
  ④向文档中添加内容。
  document.add(new Paragraph("Hello World"));
  ⑤关闭文档。
  document.close();
  通过上面的5个步骤,就能产生一个Helloworld.PDF的文件,文件内容为"Hello World"。
  建立com.lowagie.text.Document对象的实例
  com.lowagie.text.Document对象的构建函数有三个,分别是:
  public Document();
  public Document(Rectangle pageSize);
  public Document(Rectangle pageSize,
  int marginLeft,
  int marginRight,
  int marginTop,
  int marginBottom);