2013-08-05 29 views
0

如何在itextSharp生成的pdf上放置圖像?ItextSharp - RazorPdf把圖像放在Pdf

我有在控制器的簡單方法...

public ActionResult Pdf() 
    { 

     var pdfResult = new PdfResult(null,"Pdf"); 
     pdfResult.ViewBag.Title = "Title"; 

     return pdfResult; 
    } 

和一個簡單的觀點...

@{ 
    Layout = null; 
} 

<itext creationdate="@DateTime.Now.ToString()" producer="RazorPDF"> 

    Html Text for test. 

    <img src="~/Images/sampleImage.png" /> 

</itext> 

任何幫助,將不勝感激!

回答

1

嘗試:

<image url="@Context.Server.MapPath("~/Images/sampleImage.png")" />

,並在檢查了樣品在github

+0

Marc如何將自定義高度和寬度添加到圖像而不是重新調整大小? – Nikitesh

+0

這應該被標記爲答案。 – joetinger

+0

@NikiteshKolpe我從來沒有能夠找到,但我通常只是把它放到一個表中,並在'

'。該圖像似乎可以縮放 – joetinger

0

只是改變源,如下圖所示:

<img src="@Context.Server.MapPath("~/Images/sampleImage.png")" width="100" height="100"/> 
0

這個工作對我來說:

<div style="margin:auto;width:60%;padding:10px;"> 
    <img src="@Server.MapPath("~/assets/img/image.png")" /> 
</div> 
相關問題