I am creating a PDF programmatically using iTextSharp and generating a PdfPTable.
In some of the cells I need to have a hyperlink.
Without a hyperlink I can align the text in the cell horizontally and vertically, however when I add in the chunk which contain my hyperlink, the cell looses its alignment property.
Here is my code...
var webAddress = new Chunk(row["product_code"].ToString(), linkFont);
webAddress.SetAnchor(row["url"].ToString());
PdfPCell ProductCodeCell = new PdfPCell();
ProductCodeCell.AddElement(webAddress);
ProductCodeCell.VerticalAlignment = Element.ALIGN_MIDDLE;
ProductCodeCell.HorizontalAlignment = Element.ALIGN_CENTER;
ProductCodeCell.Padding = 3f;
table.AddCell(ProductCodeCell);
Can anyone help me realign the link?
Many thanks.
See this answer for a discussion on Text Mode versus Composite Mode. Basically, if you use
AddElement()
you need to set the alignment on your object instead of the cell itself.Chunk
doesn't have alignment, however, so you need to wrap your chunk in something that does which is theParagraph
.