2017-06-29 50 views
-1

我正在使用iTextSharp创建PDF并尝试在PDF的标题中添加图像。代码是这样的图像丢失的大小iTextSharp

public override void OnOpenDocument(PdfWriter writer, Document document) 
{ 
    image = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("~/Content/images/HSBC/hsbc.png")); 
    image.ScaleAbsoluteHeight(25); 
    image.ScaleAbsoluteWidth(134); 
    image.SetAbsolutePosition(38, 800); 
} 

注意:实际的图像大小是高度:25px和宽度:134px。这就是我分别在image.ScaleAbsoluteHeight(25)image.ScaleAbsoluteWidth(134)中给出的。

但我不明白为什么在生成PDF时图像变大,而且看起来很糟糕。

感谢

回答

0

你必须改变你的一样代码:

var imagepath = Server.MapPath("~/Images/logo.jpg"); 
      iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imagepath); 
      image.SetAbsolutePosition(440, 10); 
      image.ScaleToFit(120f, 155.25f); 

这肯定会为你工作。

干杯!