Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top