Cordova-pdf生成器:无法使用相对路径绑定图像

iyfjxgzm  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(134)

我正在使用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的位置与模板的原始位置不同,但我就是不能找出正确的路径。

svmlkihl

svmlkihl1#

如果您尝试访问设备上的映像,则可能需要安装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);

相关问题