cordova-print-pdf-plugin
cordova-print-pdf-plugin copied to clipboard
printer show, but it keep loading preview
As title, ios show a printer pop up, but the content is keep loading preview. firstly i try to use URI but not work. then i change the way to use base64. from file pdf on local. i use cordovafile.readAsDataURL to convert file pdf to base64. but it still not work. please help me.
below is my code. could you take a look at it success is returned base64string $cordovaFile.readAsDataURL(pathDirectory, fileName) .then(function (success) { window.plugins.PrintPDF.isPrintingAvailable( function(isAvailable) {
alert('printing is success: '+ success.substring(0,200));
if(isAvailable){
window.plugins.PrintPDF.print({
data: success,
type: 'Data',
title: fileName,
success: function(){
alert('success');
},
error: function(data){
data = JSON.parse(data);
alert('failed: ' + data.error);
}
});
}
});
//alert(JSON.stringify(success));
}, function (error) {
alert(JSON.stringify(error));
});
I'm experiencing the same issue, any update on this?
Hello,
I also am experiencing this same issue. I have tried to use this code with type: 'File' and the data is a URL to a pdf that I am storing in my expansion file. The printer preview opens then my app crashes. Is this plugin compatible with this cordova plugin? -- > https://github.com/agamemnus/cordova-plugin-xapkreader#cordova-5.0
If you could provide an example of how to open a pdf from an expansion file and convert it to a base64 string that would be extremely helpful, because I can't get that to work either.
I got it working. Turned out my data was not correctly base64 encoded
How did you get it properly base64 encoded? Were you using a local pdf file or a pdf hosted on a server? I am trying to figure out how to encode a pdf file located in my expansion file with no success.
My app is taking to a nodejs REST API, so I just modified the API to return the PDF content as a Base64 string and it worked.
If you're trying to do this client side, you might be able to use FileReader.readAsDataURL(). Just remember to strip the data:application/pdf;base64,
part of the output string before passing it to the plugin as suggested in the docs
Yes, I have tried to do this client side but can't seem to get the PDF to open or be served locally. I have tried the below code var files = new File([""], "filename.pdf",{type:'application/pdf'}); console.log(files); if (files.length > 0) { getBase64(files[0]); } });
function getBase64(file) { var reader = new FileReader(); reader.readAsDataURL(file); reader.onload = function () { console.log(reader.result); }; reader.onerror = function (error) { console.log('Error: ', error); }; }
where filename.pdf is a pdf stored in my expansion file and it does not read it in as a proper array/file type. I keep getting file size 0...