itextpdf: how to insert a new page when a table splits?

笑着哭i 提交于 2019-12-25 07:39:37

问题


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.

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.

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 )
   {
   }

}

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.

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

Does anyone know how to do this?


回答1:


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.



来源:https://stackoverflow.com/questions/17497215/itextpdf-how-to-insert-a-new-page-when-a-table-splits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!