简体   繁体   English

图像上的Horizo​​ntalAlignment在itextsharp中的PdfPCell中不起作用

[英]HorizontalAlignment on image not working in PdfPCell in itextsharp

I am adding a image in PdfPCell and i want that to be center aligned. 我在PdfPCell中添加一个图像,我希望它是中心对齐的。 For that i used 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 谢谢

您需要在图像上设置对齐方式,而不是单元格:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM