Issue
I am generating pdf
files using cordova-pdf-generator
plugin, and I can't bind an image using a relative path.
I have already tried using file://
protocol and ng-scr
instead of src
, but it didn't do the trick.
To make it way more simpler, I did locate both template and image in the same folder.
src\assets\template.html
src\assets\logo.png
The HTML
tag looks like:
<img ng-src="logo.png" alt="logo" height="40px" />
The image would just appear broken in the generated pdf. I guess this is happening because the location of the generated pdf is different from the origin location of the template, but I just can't figure it out which should be the correct path.
Solution
If you are trying to access images on a device you will likely need to install cordova-plugin-file
cordova plugin add cordova-plugin-file
With the plugin installed you can access via the cdvfile
protocol.
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#cdvfile-protocol
Example from 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);
Answered By - chrismclarke
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.