The following code creates two identical tables with a single cell. One of them is aligned to the left and the other is centered. The problem is that the tables don't look alike in the generated pdf. For some reason, the contents of the left-aligned table don't seem to fit inside the cell (the string wraps around and takes up two lines).
Any ideas? Am I doing something wrong or did I just come across a bug?
public class Test { public static void main(String[] args) { try { Document doc = new Document(PageSize.LETTER, 0, 0, 0, 0);
PdfWriter.getInstance(doc, new FileOutputStream("test.pdf"));
doc.open();
PdfPTable table1 = createTable();
table1.setHorizontalAlignment(Table.ALIGN_LEFT);
doc.add(table1); PdfPTable table2 = createTable();
doc.add(table2); doc.close();
}
catch (Exception e) {
e.printStackTrace();
}
} private static PdfPTable createTable()
throws Exception
{
PdfPTable table = new PdfPTable(1); Font font = FontFactory.getFont("Helvetica", 12);
String value = "MMMMMMM";
float width = font.getBaseFont().getWidthPoint(value, font.size()); // table.setTotalWidth(new float[] {width}); -- doesn't seem to work
table.setWidthPercentage(new float[] { width }, PageSize.LETTER ); PdfPCell cell = new PdfPCell(new Phrase(value, font));
cell.setPadding(0);
table.addCell(cell);return table; } }
Thanks!
Martin
_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail
------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ iText-questions mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/itext-questions
