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

Reply via email to