Hi Paulo,

I've found out that the extra vertical space between Paragraph and
PdfPTable vanishes when I call my version of fitsPage first, with your
implementation this extra space remains.

I know this is a side effect of my fitsPage implementation, but isn't
this the correct behaviour?

Best regards,
Christian


On Sun, 2004-09-26 at 12:31, Christian Lauer wrote:
> Hi Paulo,
> 
> what means 'mixing other elements'?
> 
> I've added a small test program which mixes PdfPTables, Paragraphs and
> Lists and the position returned by my getVerticalPosition has been
> correct for all test cases. OK it will only work on document level but
> that's absolutely OK for me. 
> 
> By the way, can you explain the big amount between the second paragraph
> and the first PdfPTable, shouldn't it be aligned to the rule like the
> second PdfPTable does?
> 
> Best regards,
> Christian
> 
> On Sat, 2004-09-25 at 13:10, Paulo Soares wrote:
> > That won't work if you are mixing other elements. Try this in PdfDocument:
> > 
> >     boolean fitsPage(PdfPTable table, float margin) {
> >         if (!table.isLockedWidth()) {
> >             float totalWidth = (indentRight() - indentLeft()) *
> > table.getWidthPercentage() / 100;
> >             table.setTotalWidth(totalWidth);
> >         }
> >         newLine();
> >         flushLines();
> >         return table.getTotalHeight() + 0.001f <= indentTop() -
> > currentHeight - indentBottom() - margin;
> >     }
> > 
> > Best Regards,
> > Paulo Soares
> > 
> > ----- Original Message ----- 
> > From: "Christian Lauer" <[EMAIL PROTECTED]>
> > To: "Paulo Soares" <[EMAIL PROTECTED]>
> > Cc: "iText Mailing List" <[EMAIL PROTECTED]>
> > Sent: Saturday, September 25, 2004 10:34
> > Subject: RE: [iText-questions] ColumnText
> > 
> > 
> > > Hi Paulo,
> > >
> > > I've extended PdfWriter and PdfDocument to make my solution work:
> > >
> > > PdfWriter:
> > >     /**
> > >      * Gets the current vertical page position.
> > >      *
> > >      * @return The current vertical page position.
> > >      */
> > >     public float getVerticalPosition() {
> > >         return pdf.getVerticalPosition();
> > >     }
> > >
> > > PdfDocument:
> > >     /**
> > >      * Gets the current vertical page position.
> > >      *
> > >      * @return The current vertical page position.
> > >      */
> > >     public float getVerticalPosition() {
> > >         return top() -  currentHeight - indentTop;
> > >     }
> > >
> > > What do you think about this patch?
> > >
> > > Best regards,
> > > Christian
> > >
> > > On Wed, 2004-09-22 at 16:23, Paulo Soares wrote:
> > > > The code is exactly the same as in addPTable().
> > > >
> > > > Best Regards,
> > > > Paulo Soares
> > > >
> > > > > -----Original Message-----
> > > > > From: [EMAIL PROTECTED]
> > > > > [mailto:[EMAIL PROTECTED] On
> > > > > Behalf Of Steve Appling
> > > > > Sent: Wednesday, September 22, 2004 12:15 PM
> > > > > To: Christian Lauer; iText Mailing List
> > > > > Subject: Re: [iText-questions] ColumnText
> > > > >
> > > > > Do you think ColumnText should implement Element?  Then you
> > > > > could add a form
> > > > > of setSimpleColumn that only sets height and width and the add call in
> > > > > PdfDocument could adjust for horizontal alignment and call
> > > > > the existing
> > > > > setSimpleColumn using the currentHeight and indents (like it does in
> > > > > addPTable).
> > > > >
> > > > > ----- Original Message ----- 
> > > > > From: "Christian Lauer" <[EMAIL PROTECTED]>
> > > > > To: "iText Mailing List" <[EMAIL PROTECTED]>
> > > > > Sent: Wednesday, September 22, 2004 2:44 AM
> > > > > Subject: [iText-questions] ColumnText
> > > > >
> > > > >
> > > > > > Hi Paulo,
> > > > > >
> > > > > > I'd like to enhance the support of ColumnText in UJAC. For
> > > > > that I'd like
> > > > > > to add a column text seamlessly to the document like other
> > > > > elements like
> > > > > > tables, paragraphs or lists do. To make that happen I need
> > > > > to know the
> > > > > > current page position. To get this, I tried the following
> > > > > workaround,
> > > > > > which works, but adds a huge spacing between the current
> > > > > text and the
> > > > > > column text.
> > > > > >
> > > > > >
> > > > > >   public float getVerticalPosition() throws
> > > > > DocumentHandlerException {
> > > > > >     try {
> > > > > >       Table tab = new Table(1);
> > > > > >       return ((PdfWriter) documentWriter).getTableBottom(tab);
> > > > > >     } catch (BadElementException ex) {
> > > > > >       throw new DocumentHandlerException(locator(), ex.getMessage(),
> > > > > > ex);
> > > > > >     }
> > > > > >   }
> > > > > >
> > > > > >
> > > > > > Is there a better solution?
> > > > > >
> > > > > > Best regards,
> > > > > > Christian
> > > > > >
> > > > > >
> > > > > >
> > > > > > -------------------------------------------------------
> > > > > > This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
> > > > > > Project Admins to receive an Apple iPod Mini FREE for your
> > > > > judgement on
> > > > > > who ports your project to Linux PPC the best. Sponsored by IBM.
> > > > > > Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
> > > > > > _______________________________________________
> > > > > > iText-questions mailing list
> > > > > > [EMAIL PROTECTED]
> > > > > > https://lists.sourceforge.net/lists/listinfo/itext-questions
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > -------------------------------------------------------
> > > > > This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
> > > > > Project Admins to receive an Apple iPod Mini FREE for your
> > > > > judgement on
> > > > > who ports your project to Linux PPC the best. Sponsored by IBM.
> > > > > Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
> > > > > _______________________________________________
> > > > > iText-questions mailing list
> > > > > [EMAIL PROTECTED]
> > > > > https://lists.sourceforge.net/lists/listinfo/itext-questions
> > > > >
> > > -- 
> > > Christian Lauer <[EMAIL PROTECTED]>
> > >
-- 
Christian Lauer <[EMAIL PROTECTED]>
package ujac.test.itext;

import java.awt.Color;
import java.io.FileOutputStream;

import com.lowagie.text.Document;

import com.lowagie.text.Chunk;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.List;
import com.lowagie.text.ListItem;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;

import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

public class VerticalPositionTest {
  
  private static void drawRule(Document document, PdfWriter documentWriter) {
    float pageWidth = document.getPageSize().width();
    float verticalPos =  documentWriter.getVerticalPosition();
    PdfContentByte cb = documentWriter.getDirectContent();
    cb.saveState();
    cb.setColorStroke(Color.BLACK);
    cb.setLineWidth(1.0F);
    cb.moveTo(0, verticalPos);
    cb.lineTo(pageWidth, verticalPos);
    cb.closePathStroke();
    cb.restoreState();
  }

  private static void addListItem(List list, String label, Font font) {
    ListItem li = new ListItem(label, font);
    li.setSpacingBefore(5);
    li.setSpacingAfter(5);
    list.add(li);
  }

  private static List buildList(float symbolIndent, Font font) {
    List list = new List(true, false, symbolIndent);
    addListItem(list,"One", font);
    addListItem(list,"Two", font);
    addListItem(list,"Three", font);
    addListItem(list,"Four", font);
    addListItem(list,"Five", font);
    addListItem(list,"Six", font);
    addListItem(list,"Seven", font);
    addListItem(list,"Eight", font);
    addListItem(list,"Nine", font);
    return list;
  }
  public static void main(String[] args) {
    
    try {
      FileOutputStream os = new FileOutputStream("verticalPositionTest.pdf");
      Document document = new Document(PageSize.A4, 25, 25, 25, 25);
      PdfWriter documentWriter = PdfWriter.getInstance(document, os);
      
      document.open();
      Font font = new Font(Font.HELVETICA, 10);
      Font font2 = new Font(Font.HELVETICA, 12);
      Font font3 = new Font(Font.TIMES_ROMAN, 14);

      Paragraph p1 = new Paragraph("paragraph 1", font);
      p1.setSpacingAfter(174);
      document.add(p1);
      drawRule(document, documentWriter);

      Paragraph p2 = new Paragraph("paragraph 2", font2);
      p2.setSpacingAfter(90);
      document.add(p2);
      drawRule(document, documentWriter);

      PdfPTable tab1 = new PdfPTable(new float[] {100});
      tab1.setWidthPercentage(100);
      for (int i = 0; i < 25; i++) {
        PdfPCell c = new PdfPCell(new Phrase(Integer.toString(i), font));
        tab1.addCell(c);
      }
      documentWriter.fitsPage(tab1);
      document.add(tab1);
      drawRule(document, documentWriter);

      PdfPTable tab2 = new PdfPTable(new float[] {20, 20, 20, 20, 20});
      tab2.setWidthPercentage(100);
      for (int i = 0; i < 25; i++) {
        PdfPCell c = new PdfPCell(new Phrase(Integer.toString(i), font3));
        tab2.addCell(c);
      }
      documentWriter.fitsPage(tab2);
      document.add(tab2);
      drawRule(document, documentWriter);
      
      document.add(buildList(10, font2));
      drawRule(document, documentWriter);
      
      Paragraph p3 = new Paragraph("paragraph 3", font3);
      p3.setSpacingAfter(90);
      document.add(p3);
      drawRule(document, documentWriter);
      
      document.close();
      documentWriter.close();
      
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  
}

Attachment: verticalPositionTestWithMyFitsPage.pdf
Description: Adobe PDF document

Attachment: verticalPositionTestWithPaulosFitSpace.pdf
Description: Adobe PDF document

Attachment: verticalPositionTestWithMyFitsPage.pdf
Description: Adobe PDF document

Reply via email to