2017-06-13 26 views
1

我使用this open source library为html转换为pdf。一切正常,但是当添加<img src>标签时,它不会以PDF格式显示我想要的图像。例如,html to pdf ASP.NET.Core 1.1转换后不显示图像

string image = "~/images/test.png"; 
string htmlToConvert = string.Format(@" 
<div> 
    <table>  
     <tr> 
      <td> 
       <img srcset='{0}'> 
      </td> 
     </tr>   
    </table> 
</div>", image); 

我的格式有什么问题吗?或者它只是不支持图像?如果它是真的,任何工作库为asp.net核心1.1? (重要的是因为一些库/建议基于1.0,其中包含project.json文件)

p.s.我将通过Azure Web应用程序服务部署它

回答

1

图像必须位于phantomjs执行文件所在的文件夹中。

只要看一看方法 PdfGenerator.WriteHtmlToTempFile

在那里,你可以看到你的HTML被存储在phantomjs安装目录中的文件。这是你的html文件的根,这意味着图像也必须存在。

https://github.com/TheSalarKhan/PhantomJs.NetCore/blob/master/PdfGenerator.cs

我建议你直接使用phantomjs-executabels来更好地理解发生了什么。

+0

解决了它。 'srcset'也需要更改为'src',这解决了它。谢谢Aedvald。 – pavilion