Rotativa/Wkhtmltopdf图像不显示 [英] Rotativa / Wkhtmltopdf images not displaying
问题描述
我当前正在创建MVC 4 Web应用程序.
I am currently creating an MVC 4 web application.
我有一个动作,该动作的基本背景图像始终与箭头图像相同,箭头图像的角度根据动作中收集的信息而变化.
I have an action that has a base background image which is always the same then an arrow image which changes in degrees depending on the information that is collected within the action.
我使用
<img src="@Url.Action("trend-image", "NonReg_Reports")" alt="background" width="245" height="105" />
在被调用并且仅显示HTML网页时,此方法工作正常.它给了我HTML.
This works fine when it is called and is just displaying a HTML webpage. It gives me the HTML.
<img src="/nonreg-report/01495344/trend-image" alt="background" width="245" height="105">
然后,我使用Rotativa/Wkhtmltopdf将HTML页面转换为PDF.这将运行与上面相同的代码.
I am then using Rotativa / Wkhtmltopdf to convert this HTML page into a PDF. This runs the same piece of code as above.
问题是,如果使用上面的代码,我只会得到一个带有替代文本的白框.
The problem is I am just getting a white box with the alternative text in it if I use the code above.
如果我使用< img src =〜/Content/images/trend_back_medium.png" alt ="astuff"/>
(这是我项目中的实际背景图片),则效果很好.
If I use <img src="~/Content/images/trend_back_medium.png" alt="astuff" />
which is the actual background image in my project it works fine.
由于使用方法,上述代码中的图像无法保存在任何地方.我认为这是一个路径问题,但是尝试了许多不同的操作后,我仍然无法使它正常工作.
The image from the code above can not be saved anywhere due to how it is used. I am thinking that it is a path problem, but after trying lots of different things I can still not get it to work.
任何建议或帮助将不胜感激,谢谢.
Any suggestions or help would be greatly appreciated Thank you.
推荐答案
我遇到了同样的问题.正常的html视图可以显示图片,而pdf无法显示.我用Server.MapPath指向图片,没关系...
I had the same problem. Normal html view was ok with pictures, pdf was not display it. I used Server.MapPath to point to picture and it was ok...
<img src="@Server.MapPath("~/Folder/SubFolder/Subfolder/ImageName.png")" />
我希望这会有所帮助
亚当
这篇关于Rotativa/Wkhtmltopdf图像不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!