【问题标题】:html to pdf ASP.NET.Core 1.1 image not showing after conversionhtml 到 pdf ASP.NET.Core 1.1 图像在转换后不显示
【发布时间】:2017-06-13 23:44:50
【问题描述】:

我正在使用 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 core 1.1 的工作库? (很重要,因为一些库/建议基于包含 project.json 文件的 1.0)

附言我将通过 Azure Web 应用服务部署它

【问题讨论】:

    标签: phantomjs html-to-pdf asp.net-core-1.1


    【解决方案1】:

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

    看看方法 PdfGenerator.WriteHtmlToTempFile

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

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

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

    【讨论】:

    • 解决了。 srcset 也需要更改为 src 并且这解决了它。谢谢 Aedvald。
    猜你喜欢
    • 2015-10-26
    • 2013-02-22
    • 1970-01-01
    • 2013-07-03
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-19
    相关资源
    最近更新 更多