itextpdf:表拆分时如何插入新页面? [英] itextpdf: how to insert a new page when a table splits?

查看:191
本文介绍了itextpdf:表拆分时如何插入新页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iTextPdf 5.4.1。
我有一个包含许多行的表,当表自动拆分到下一页时,我想插入一个Image,然后是另一个分页符继续表的行。

I'm using iTextPdf 5.4.1. I have a table with many rows in it, and when the table auto-splits to the next page, I want to insert an Image and then another page break to continue the table's rows.

例如:假设一张桌子根据它的行数占用2页。


最终输出应为:

第1页:适合第一页的表格行

第2页:图像

第3页:剩余的表格行。

For example: say a table will take up 2 pages based on the number of rows it has.

The final output should be:
page 1: table rows that fit on first page
page 2: image
page 3: remaining table rows.

因此,每次表格拆分时,我想插入图像然后分页。

So, each time the table splits, i want to insert an image and then a page break.

我正在尝试使用PdfPTableEventSplit接口,如下所示:

I'm trying to use the PdfPTableEventSplit interface, as follows:

public class TableSplitEvent implements PdfPTableEventSplit
{
   private Image pageImage;
   private Document pdfDoc;

   public TableSplitEvent( Image pageImage, Document pdfDoc )
   {
      super();
      this.pageImage = pageImage;
      this.pdfDoc = pdfDoc;
   }

   @Override
   public void splitTable( PdfPTable table )
   {
      try
      {
         pdfDoc.add( pageImage );
         pdfDoc.newPage();
      }
      catch ( DocumentException e )
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }

   @Override
   public void tableLayout( PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart,
                            PdfContentByte[] canvases )
   {
   }

}

然而,这似乎不起作用,因为事件似乎在呈现表之后以及在写入pdf之前被调用。

However, that doesn't seem to work as the event seems to get called after the table is rendered and before it is written to the pdf.

我得到:

第1页:图片

第2页:表格行

第3页:表行

I'm getting:
page 1: image
page 2: table rows
page 3: table rows

有谁知道怎么做?

推荐答案

如果我没弄错的话,我们收到了一个名为 PdfPTableEventAfterSplit 的事件的代码贡献。它将在几周内集成到iText中,并在7月底发布。在此之前,iText无法满足您的需求。感谢您的耐心等待。

If I'm not mistaken, we've received a code contribution for an event called PdfPTableEventAfterSplit. It will be integrated into iText in a couple of weeks and released by the end of July. Before that date, iText can't meet your needs. Thank you for your patience.

这篇关于itextpdf:表拆分时如何插入新页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆