开发者

Vertical alignment not working in composite mode

The following should work according to the documentation but it's not working for me. Am I missing something?

P开发者_StackOverflow社区dfPTable 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


Ah. You need to set the PdfCell's vertical alignment, not the paragraph.

PdfPCell c = new PdfPCell();
c.setVerticalAlignment(Element.ALIGN_MIDDLE);
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜