开发者

HorizontalAlignment on image not working in PdfPCell in itextsharp

开发者 https://www.devze.com 2023-04-09 10:24 出处:网络
I am adding a image in PdfPCell and i want that to be center aligned. For that i 开发者_如何学Goused following code but its not working

I am adding a image in PdfPCell and i want that to be center aligned. For that i 开发者_如何学Goused following code but its not working

            PdfPTable Outertable = new PdfPTable(1);
            PdfPCell celltop = new PdfPCell(new Phrase(" "));
            iTextSharp.text.Image img10 = iTextSharp.text.Image.GetInstance(@"F:\TestPDFGenerator\TestPDFGenerator\TestPDFGenerator\Sumit.JPG");
            img10.ScaleAbsolute(50, 1);
            celltop.AddElement(img10);
            celltop.HorizontalAlignment = Element.ALIGN_CENTER;
            Outertable.AddCell(celltop);

please can you tell where i am wrong

Thanks


You need to set the alignment on the image, not the cell:

img10.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
0

精彩评论

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