【发布时间】:2016-08-10 09:46:15
【问题描述】:
在我服务器的public/images 文件夹中,我上传了jpg image,2048x1536 像素和290 kb。
我已经在 MySQL 表数据库中记住了字段 Pic 这个链接:http://mywebserver.xxx/aspx/public/images/IMG0006A.jpg
我需要使用 iTextSharp library 在 pdf 文件上打印此图像并调整此图像的大小,因为它的原始文件大小超出了 pdf 页。
我找到了类似的question,我尝试了这个建议但没有成功,因为在输出中打印在 pdf 文件上的 jpg 图像总是在页面之外。
如何解决这个问题?
你能帮帮我吗?
提前谢谢你,我的代码如下。
.aspx 标记
<table border="1">
<tr>
<td colspan="2">
<label for="Pic">
Pic<br />
</label>
<asp:Image ID="Pic" runat="server" /></td>
</tr>
</table>
.cs 代码隐藏
if (!String.IsNullOrEmpty(reader["Pic"].ToString()))
{
lbPic.ImageUrl = reader["Pic"].ToString();
iTextSharp.text.pdf.PdfPCell imgCell1 = new iTextSharp.text.pdf.PdfPCell();
iTextSharp.text.Image img1 = iTextSharp.text.Image.GetInstance(Server.MapPath("\\public\\images\\IMG0006A.jpg"));
imgCell1.AddElement(new Chunk(img1, 0, 0));
img1.ScaleToFit(120f, 155.25f);
img1.ScaleAbsolute(120f, 155.25f);
}
【问题讨论】:
-
我想知道图像是如何显示的,因为您的单元格和图像对象都超出了该 sn-p 末尾的范围而没有其他用途..
-
我不确定您是否需要同时使用
ScaleAbsolute和ScaleToFit。
标签: c# mysql asp.net pdf itext