【问题标题】:Cordova-pdf-generator: Can't bind image using relative pathCordova-pdf-generator:无法使用相对路径绑定图像
【发布时间】:2019-08-29 13:26:16
【问题描述】:

我正在使用cordova-pdf-generator 插件生成pdf 文件,但我无法使用相对路径绑定图像。

我已经尝试过使用file:// 协议和ng-scr 而不是src,但它没有成功。 为了让它更简单,我确实在同一个文件夹中找到了模板和图像。

src\assets\template.html
src\assets\logo.png

HTML 标签看起来像:

<img ng-src="logo.png" alt="logo" height="40px" />

图像在生成的 pdf 中只会出现损坏。我猜这是因为生成的 pdf 的位置与模板的原始位置不同,但我无法弄清楚应该是正确的路径。

【问题讨论】:

标签: cordova pdf ionic-framework mobile


【解决方案1】:

如果您尝试访问设备上的图像,您可能需要安装 cordova-plugin-file

cordova plugin add cordova-plugin-file

安装插件后,您可以通过cdvfile 协议访问。 https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#cdvfile-protocol

来自https://github.com/cesarvr/pdf-generator/issues/38的示例

 pdf.htmlToPDF({
        data: "<html> <h1>  Hello World  </h1> <img src='cdvfile://localhost/persistent/test.png'></html>",
        documentSize: "A4",
        landscape: "portrait",
        type: "share" //use share to open the open-with-menu.
    }, this.success, this.failure);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 2017-04-20
    • 2015-09-20
    • 2017-06-19
    • 1970-01-01
    • 2019-02-08
    相关资源
    最近更新 更多