The following should work according to the documentation but it's not working for me. Am I missing something?
PdfPTable rs1 = new PdfPTable(1);
PdfPCell c = new PdfPCell();
Paragraph p = new Paragraph("some text to align");
c.AddElement(p);
c.VerticalAlignment = Element.ALIGN_MIDDLE;
rs1.AddCell(c);
rs1.AddCell("more text");
return rs1;
The thing with iTextSharp is that it will behave differently depending on which constructor you use. This won't align the text:
PdfPCell c = new PdfPCell();
c.Add(new Phrase("Whatever"));
c.setHorizontalAlignment(Element.ALIGN_CENTER);
But this will:
PdfPCell c = new PdfPCell(new Phrase("Whatever"));
c.setHorizontalAlignment(Element.ALIGN_CENTER);
I don't know exactly why this is, it's got something to do with the cell being in 'text mode' if you add the phrase in the constructor versus 'composite mode' if you add it later (in which case each object is supposed to look after it's own alignment).
Some more info (in Java, but still applies) http://tutorials.jenkov.com/java-itext/table.html#cell-modes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With