Hello Bruno!

Have done some modifications to PdfDocument.add(Element) again since I
noticed the following:
If a table has a header and a page is filled to such an extent that only the
header fits the page and the table needs to be continued on the next page ..
then (in case the property cellsFitPage is set to true) dont draw the header
in the remaining page area since anyways it will be repeated on next page!

Here is the modified code for the TABLE case (between G.F. start change and
G.F. end change) within the cell iterator loop:

      boolean headerChecked = false;
      for (ListIterator iterator = cells.listIterator(); iterator.hasNext()
&& !tableHasToFit;)
      {
       cell = (PdfCell) iterator.next();
       // G.F. start change
       if( cellsHaveToFit )
       {
        if( !cell.isHeader() ) // check as it has been done before
        {
         if (cell.rownumber() != currentRownumber)
         {
          boolean cellsFit = true;
          currentRownumber = cell.rownumber();
          int cellCount = 0;
          while (cell.rownumber() == currentRownumber && cellsFit &&
iterator.hasNext())
          {
           if (cell.bottom() < indentBottom())
           {
            cellsFit = false;
           }
           cell = (PdfCell) iterator.next();
           cellCount++;
          }
          if (!cellsFit)
          {
           break;
          }
          for (int i = cellCount; i >= 0; i--)
          {
           cell = (PdfCell) iterator.previous();
          }
         }
        }
        else
        {
         if( !headerChecked ) // check header once only
         {
          headerChecked = true;
          boolean cellsFit = true;
          int cellCount = 0;
          float firstTop = cell.top();
          // check if header cells fit page
          while (cell.isHeader() && cellsFit && iterator.hasNext())
          {
           if (firstTop - cell.bottom(0) > indentTop() - currentHeight -
indentBottom())
           {
            cellsFit = false;
           }
           cell = (PdfCell) iterator.next();
           cellCount++;
          }
          // check if at least one data line fits page
          currentRownumber = cell.rownumber();
          while (cell.rownumber() == currentRownumber && cellsFit &&
iterator.hasNext())
          {
           if (firstTop - cell.bottom(0) > indentTop() - currentHeight -
indentBottom() - 10.0)
           {
            cellsFit = false;
           }
           cell = (PdfCell) iterator.next();
           cellCount++;
          }
          for (int i = cellCount; i >= 0; i--)
          {
           cell = (PdfCell) iterator.previous();
          }
          if (!cellsFit)
          {
           // remove header cells since will be drawn automatically in code
further down
           while( cell.isHeader() )
           {
            iterator.remove();
            cell = (PdfCell) iterator.next();
           }
           break;
          }
         }
        }
        // G.F. end change
       }
       lines = cell.getLines(pagetop, indentBottom());
       // if there are lines to add, add them
       if (lines != null && lines.size() > 0)
       {
        // we paint the borders of the cells
        cellsShown = true;
        cellGraphics.rectangle(cell.rectangle(pagetop, indentBottom()));
        lostTableBottom = Math.max(cell.bottom(), indentBottom());

        // we write the text
        float cellTop = cell.top(pagetop - oldHeight);
        text.moveText(0, cellTop);
        cellDisplacement = flushLines() - cellTop;
        text.moveText(0, cellDisplacement);
        if (oldHeight + cellDisplacement > currentHeight)
        {
         currentHeight = oldHeight + cellDisplacement;
        }
       }
       ArrayList images = cell.getImages(pagetop, indentBottom());
       for (Iterator i = images.iterator(); i.hasNext();)
       {
        cellsShown = true;
        Image image = (Image) i.next();
        addImage(graphics, image, 0, 0, 0, 0, 0, 0);
       }
       // if a cell is allready added completely, remove it
       if (cell.mayBeRemoved())
       {
        iterator.remove();
       }
      }

Hope this change can be included as standard for next version.

Regards,
Gerald.



-------------------------------------------------------
This sf.net emial is sponsored by: Influence the future of 
Java(TM) technology. Join the Java Community Process(SM) (JCP(SM)) 
program now. http://ad.doubleclick.net/clk;4699841;7576301;v?
http://www.sun.com/javavote
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to