html 到 pdf ASP.NET.Core 1.1 图像在转换后不显示

html to pdf ASP.NET.Core 1.1 image not showing after conversion

我正在使用 this open source library 将 html 转换为 pdf。一切正常,但在添加 <img src> 标签时,它没有显示我想要的 PDF 图像。例如,

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 的任何工作库? (很重要,因为一些 libraries/suggestions 基于包含 project.json 文件的 1.0)

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

图像必须与 phantomjs 可执行文件位于同一文件夹中。

看看方法就知道了 PdfGenerator.WriteHtmlToTempFile

在那里你可以看到你的 html 存储在 phantomjs-installation 目录中的一个文件中。这是您的 html 文件的根目录,这意味着图像也必须在那里。

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

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