我正在创建一个单独的pdf页面,在表格中有6个独立的单元格图像,即使我在服务器端设置图像的高度和宽度与ScaleToFit完全相同,但在pdf页面上的图像大小并不相同。
有没有办法让所有图像的大小完全相同?
PdfPTable table = new PdfPTable(3);
table.HorizontalAlignment = Element.ALIGN_CENTER;
table.WidthPercentage = 100;
table.TotalWidth = 698.5f;
table.LockedWidth = true;
table.SetWidths(new float [] {1,1,1});
iTextSharp.text.Image img1 = iTextSharp.text.Image.GetInstance("C:\\Users\\DaNet\\Downloads\\image.jpg");
img1.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
img1.ScaleToFit(120f, 155.25f);
iTextSharp.text.pdf.PdfPCell imgCell1 = new iTextSharp.text.pdf.PdfPCell(img1);
imgCell1.HorizontalAlignment = Element.ALIGN_CENTER;
imgCell1.BackgroundColor = new BaseColor(255, 255, 255);
imgCell1.Border = iTextSharp.text.Rectangle.NO_BORDER;
table.AddCell(imgCell1);发布于 2011-11-23 06:31:04
两件事。
首先,请参阅this post,了解如何将Image包装在Chunk中。基本上:
iTextSharp.text.pdf.PdfPCell imgCell1 = new iTextSharp.text.pdf.PdfPCell();
imgCell1.AddElement(new Chunk(img1, 0, 0));其次,如果您希望的大小完全相同,那么您需要使用ScaleAbsolute而不是ScaleToFit。后者保持图像的纵横比,因此缩放到适合50x50的100x200图像将显示为25x50。
img1.ScaleAbsolute(120f, 155.25f);https://stackoverflow.com/questions/8234062
复制相似问题