You have to play with the left and right padding, a nested table will always
occupy the full cell extent but you can make that extent smaller.

Best Regards,
Paulo Soares

> -----Original Message-----
> From: Khaled Alakhras [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, November 08, 2002 16:00
> To:   [EMAIL PROTECTED]
> Subject:      [iText-questions] Is it possible to center a nested
> PdfPTable in a PdfPCell?
> 
> Is it possible to center a nested PdfPTable in a PdfPCell? setting the
> cell horizontal alignment doesn't seem to work. It does work for a Phrase
> and Image but not for PdfPTable.
> 
> PdfPTable nested = new PdfPTable(2);
> cell = new PdfPCell(nested);
> cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
> table.addCell(cell);
> 
> Thanks,
> 
> Khaled
> 
>  Paulo Soares <[EMAIL PROTECTED]> wrote: 
> 
>       What I get is your desired layout. Are you sure you didn't modify
> iText to
>       not copy the inserted tables? The behavior would be this. I suppose
> that if
>       you create two independent nested tables then it would work.
>       
>       Best Regards,
>       Paulo Soares
>       
>       > -----Original Message-----
>       > From: Khaled Alakhras [SMTP:[EMAIL PROTECTED]]
>       > Sent: Thursday, November 07, 2002 17:46
>       > To: Paulo Soares; [EMAIL PROTECTED]
>       > Subject: RE: [iText-questions] Setting the colSpan on a PdfPCell
> that
>       > cont ains a PdfPTable
>       > 
>       > Maybe you are getting a different result, I am attaching the pdf
> file
>       > generated on my system: 
>       > 
>       > The desired layout: 
>       > 
>       > ---------------------------------------
>       > | | |
>       > ---------------------------------------
>       > | | 2X2 Table |
>       > ---------------------------------------
>       > | 2X2 Table |
>       > ---------------------------------------
>       > 
>       > Thanks,
>       > Khaled
>       > 
>       > Paulo Soares wrote: 
>       > 
>       > I don't get it. The first nested table fits where would be
>       > Table.Cell3 and
>       > has 2 columns, there's no spanning. Can you draw the expected
>       > layout?
>       > 
>       > Best Regards,
>       > Paulo Soares
>       > 
>       > > -----Original Message-----
>       > > From: Khaled Alakhras [SMTP:[EMAIL PROTECTED]]
>       > > Sent: Thursday, November 07, 2002 14:41
>       > > To: Paulo Soares; [EMAIL PROTECTED]
>       > > Subject: RE: [iText-questions] Setting the colSpan on a PdfPCell
>       > that
>       > > cont ains a PdfPTable
>       > > 
>       > > What you describing is the desired effect, however if you look
> at
>       > the
>       > > example, the first nested table is added to a cell with colSpan
> of
>       > 1 and
>       > > the seconed nested table is added to a cell with a colSpan of 2.
>       > The
>       > > second table shows up correctly spanning two columns, but the
>       > first nested
>       > > table shows up spanning two columns also which is incorrect. 
>       > > 
>       > > Thanks, 
>       > > 
>       > > Khaled
>       > > 
>       > > Paulo Soares wrote: 
>       > > 
>       > > Works correctly. If you have colspan 2 the nested table inside
>       > will
>       > > occupy
>       > > the two columns space instead of one. What result would you
>       > expect?
>       > > 
>       > > Best Regards,
>       > > Paulo Soares
>       > > 
>       > > > -----Original Message-----
>       > > > From: Khaled Alakhras [SMTP:[EMAIL PROTECTED]]
>       > > > Sent: Wednesday, November 06, 2002 21:37
>       > > > To: [EMAIL PROTECTED]
>       > > > Subject: [iText-questions] Setting the colSpan on a PdfPCell
>       > that
>       > > > contains a PdfPTable
>       > > > 
>       > > > It seems that there is a problem when setting the colSpan of a
>       > > PdfPCell
>       > > > that contains a PdfPTable. Setting the colSpan effects all
> other
>       > > cells
>       > > > that contain a PdfPTable also. Please see attahced example.
>       > > > 
>       > > > Thanks,
>       > > > Khaled
>       > > > 
>       > > > Test.java
>       > > > 
>       > > > import com.lowagie.text.Document;
>       > > > 
>       > > > import com.lowagie.text.PageSize;
>       > > > 
>       > > > import com.lowagie.text.Phrase;
>       > > > 
>       > > > import com.lowagie.text.pdf.PdfPCell;
>       > > > 
>       > > > import com.lowagie.text.pdf.PdfPTable;
>       > > > 
>       > > > import com.lowagie.text.pdf.PdfWriter;
>       > > > 
>       > > > import java.awt.Color;
>       > > > 
>       > > > import java.io.FileOutputStream;
>       > > > 
>       > > > 
>       > > > 
>       > > > public class Test
>       > > > 
>       > > > {
>       > > > 
>       > > > public static void main(String[] args)
>       > > > 
>       > > > {
>       > > > 
>       > > > Document document = new Document(PageSize.A4, 50, 50, 50, 50);
>       > > > 
>       > > > try
>       > > > 
>       > > > {
>       > > > 
>       > > > PdfWriter writer = PdfWriter.getInstance(document, new
>       > > > FileOutputStream("test.pdf"));
>       > > > 
>       > > > document.open();
>       > > > 
>       > > > PdfPCell cell;
>       > > > 
>       > > > PdfPTable table = new PdfPTable(2);
>       > > > 
>       > > > table.setWidthPercentage(70);
>       > > > 
>       > > > table.setHeaderRows(0);
>       > > > 
>       > > > cell = table.getDefaultCell();
>       > > > 
>       > > > cell.setBorderWidth(1);
>       > > > 
>       > > > cell.setBorderColor(Color.blue);
>       > > > 
>       > > > // Create a 2X2 sub-table
>       > > > 
>       > > > PdfPTable nested = new PdfPTable(2);
>       > > > 
>       > > > for (int k = 0; k < 4; ++k)
>       > > > 
>       > > > {
>       > > > 
>       > > > cell = new PdfPCell(new Phrase("nested.Cell " + k));
>       > > > 
>       > > > cell.setBorderWidth(1);
>       > > > 
>       > > > cell.setBorderColor(Color.blue);
>       > > > 
>       > > > cell.setBackgroundColor(Color.red);
>       > > > 
>       > > > nested.addCell(cell);
>       > > > 
>       > > > }
>       > > > 
>       > > > cell = new PdfPCell(new Phrase("Table.Cell0"));
>       > > > 
>       > > > cell.setBorderWidth(1);
>       > > > 
>       > > > cell.setBackgroundColor(Color.blue);
>       > > > 
>       > > > table.addCell(cell);
>       > > > 
>       > > > cell = new PdfPCell(new Phrase("Table.Cell1"));
>       > > > 
>       > > > cell.setBorderWidth(1);
>       > > > 
>       > > > cell.setBackgroundColor(Color.blue);
>       > > > 
>       > > > table.addCell(cell);
>       > > > 
>       > > > cell = new PdfPCell(new Phrase("Table.Cell2"));
>       > > > 
>       > > > cell.setBorderWidth(1);
>       > > > 
>       > > > cell.setBackgroundColor(Color.blue);
>       > > > 
>       > > > table.addCell(cell);
>       > > > 
>       > > > cell = new PdfPCell(nested);
>       > > > 
>       > > > cell.setBorderWidth(1);
>       > > > 
>       > > > cell.setColspan(1);
>       > > > 
>       > > > cell.setPadding(1);
>       > > > 
>       > > > table.addCell(cell);
>       > > > 
>       > > > cell = new PdfPCell(nested);
>       > > > 
>       > > > cell.setBorderWidth(1);
>       > > > 
>       > > > cell.setColspan(2); //** NOTE: setting the colspan for this
> cell
>       > > effects
>       > > > all other cells that
>       > > > 
>       > > > //** contain a table.
>       > > > 
>       > > > cell.setPadding(1);
>       > > > 
>       > > > cell.setBackgroundColor(Color.blue);
>       > > > 
>       > > > table.addCell(cell);
>       > > > 
>       > > > document.add(table);
>       > > > 
>       > > > document.close();
>       > > > 
>       > > > }
>       > > > 
>       > > > catch (Exception de)
>       > > > 
>       > > > {
>       > > > 
>       > > > de.printStackTrace();
>       > > > 
>       > > > }
>       > > > 
>       > > > }
>       > > > 
>       > > > }
>       > > > 
>       > > > 
>       > > > 
>       > > > _____ 
>       > > > 
>       > > > Do you Yahoo!?
>       > > > HotJobs -
>       > > > Search new jobs daily now
>       > > 
>       > > 
>       > > 
>       > > _____ 
>       > > 
>       > > Do you Yahoo!?
>       > > U2 on LAUNCH
>       > > -
>       > > Exclusive medley & videos from Greatest Hits CD
>       > 
>       > 
>       > 
>       > _____ 
>       > 
>       > Do you Yahoo!?
>       > U2 on LAUNCH
>       > -
>       > Exclusive medley & videos from Greatest Hits CD << File: test.pdf
> >> 
> 
> 
> 
>   _____  
> 
> Do you Yahoo!?
> U2 on LAUNCH
> <http://rd.yahoo.com/launch/mailsig/*http://launch.yahoo.com/u2> -
> Exclusive medley & videos from Greatest Hits CD


-------------------------------------------------------
This sf.net email is sponsored by: See the NEW Palm 
Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to