[英]how to set the width and height of the Image after export to PDF by ITextSharp
Currently I using ITextSharp for exporting my gridview to pdf. 目前,我使用ITextSharp将gridview导出为pdf。 My gridview have an Image file and it's width will expend to 125% and height also to 125% percent.
我的gridview有一个Image文件,它的宽度将扩展为125%,高度也将扩展为125%。 My questions are:
我的问题是:
how do i set the image to widht:80px and height:100px. 我如何将图像设置为widht:80px和height:100px。
after set the image width and height, how to insert it to the gridview? 设置图像的宽度和高度后,如何将其插入到gridview中?
besides that, after i export the gridview to pdf file, the image will go out of the cell. 除此之外,在将gridview导出为pdf文件后,图像将退出单元格。 What is that and how to solve?
那是什么以及如何解决?
See this post in MikesDotnetting . 请参阅MikesDotnetting中的这篇文章 。 Another post about working with tables in iTextsharp is also there
关于在iTextsharp中使用表的另一篇文章也在那里
See a sample code for working with tables 查看用于处理表的示例代码
// adding content to iTextSharp Document instance
PdfPTable table = new PdfPTable(3);
//actual width of table in points
table.TotalWidth = 500f;
//fix the absolute width of the table
table.LockedWidth = true;
//relative col widths in proportions
float[] widths = new float[] { 1f, 2f, 1f };
table.SetWidths(widths);
table.HorizontalAlignment = 0;
//leave a gap before and after the table
table.SpacingBefore = 20f;
table.SpacingAfter = 10f;
//Start Heading
table.AddCell(new PdfPCell() { BorderColor = BaseColor.LIGHT_GRAY, Phrase = new Phrase("No.", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)) });
table.AddCell(new PdfPCell() { BorderColor = BaseColor.LIGHT_GRAY, Phrase = new Phrase("Item Name", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)) });
table.AddCell(new PdfPCell() { BorderColor = BaseColor.LIGHT_GRAY, Phrase = new Phrase("Description", new Font(Font.FontFamily.HELVETICA, 8f, Font.BOLD)) });
// Table content
//Here we can use a loop to add multiple rows
table.AddCell(new PdfPCell() { BorderColor = BaseColor.LIGHT_GRAY, Phrase = new Phrase("1", new Font(Font.FontFamily.HELVETICA, 8f, Font.NORMAL)) });
table.AddCell(new PdfPCell() { BorderColor = BaseColor.LIGHT_GRAY, Phrase = new Phrase("Register Book"), new Font(Font.FontFamily.HELVETICA, 8f, Font.NORMAL)) });
table.AddCell(new PdfPCell() { BorderColor = BaseColor.LIGHT_GRAY, Phrase = new Phrase("Used to manage the details"), new Font(Font.FontFamily.HELVETICA, 8f, Font.NORMAL)) });
Here you can see a three column table. 在这里,您可以看到三列表格。 For adding multiple rows you can loop the table content part in the code.
要添加多行,您可以在代码中循环使用表内容部分。
Pass the values from code as shown. 如图所示传递代码中的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.