cordova-print-pdf-plugin
cordova-print-pdf-plugin copied to clipboard
Support file:// URIs
It seems the plugin only supports cdvfile:// URIs. My typical flow is to download a file through the Cordova File Transfer plugin, then use that resulting FileEntry object to get the full path of the file. However, it returns something like:
file:///var/mobile/my/file/path/document.pdf
I have to hack up a cdvfile:// URL to pass in to the plugin.
Can you please elaborate on how you "hacked" up a cdvfile:// url to pass to the plugin? I have a file stored in an expansion file that I can't seem to get to work. Any clarification would be most helpful. Thank you,
HttpService.downloadFile($scope.document.pdf_url, filename).then(function (filepath) {
window.plugins.PrintPDF.print({
data: "cdvfile://localhost/documents/" + filename,
type: 'File',
title: 'Print Document',
success: function () {
},
error: function (data) {
data = JSON.parse(data);
console.log('failed: ' + data.error);
}
});
});
Here's my download code:
downloadFile: function (url, filename) {
var deferred = $q.defer();
var fileTransfer = new FileTransfer();
var uri = encodeURI(url);
fileTransfer.download(
uri,
cordova.file.documentsDirectory + filename,
function (entry) {
deferred.resolve(entry);
},
function (error) {
deferred.reject(error);
});
return deferred.promise;
}
Let me know if that helps!
Are you downloading from a remote server then? I am trying to understand how this would actually look for my example: downloadFile($scope.document.pdf_url, filename)
what is $scope? and do I use document.'http...etc URL", filename)?
Or can I somehow reference a pdf file that I have stored in my expansion file? so it would be document.'content:///...etc", filename'
Thank you for your help
Related to this: some documentation on just want to set as the path in order to get access to the www/
files would be much appreciated. I've spent about 4 hours so far trying to get this plugin to say anything other than "File does not exist" (when it does).