I am using this code to align horizontally.
cell = New PdfPCell();
p = New Phrase("value");
cell.AddElement(p);
cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER; //Tried with Element.Align_Center Also. Tried Adding this line before adding element also.
table.AddCell(cell);
It's not working.
I am creating a table with 5 columns in it and adding cells dynamically in runtime in a for loop with above code. I want all cells content to be centered.
Per the comments, the correct answer (which I have just tested locally) is to create a paragraph element and add the alignment directive to the paragraph.
A working block of code which demonstrates this is:
Credit for this should go to the user Bruno Lowagie but there seems to be some odd drama going on, complaints of downvotes on the correct answer and subsequent deletion of the same.
I'll eat the downvotes if it gets a clear answer posted in the right place at the right time.
Some things are more important than internet-points. <3
It is possible to set alignment for all table cells as example:
if you need other alignment for some of the table cells you can specify it separately -
try this,
I know this is old question, but the proper sollution is to use
cell.HorizontalAlignment = 1;
Here is a nice example
Finally
Change this :
with this :
Looks similar but different in result I don't know why
try this,