How do I open a saved PDF file on my Android device ? #510
-
Hello everyone ! I'm generating a PDF file using jsPDF library. After that, I've been using cordova-plugin-file to write it into an Android folder. The file are been writing sucessfull ! Even into "dataDirectory" (internal) or "externalRootDirectory" (external) The problem is : I've tried to open this file, by several ways, using:
It seems to be something like a permission Thanks in advance !!! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
PDFs are complex binaries, so a pdf viewer software is necessary. The proper "android" way is to use an Intent to open the PDF document, which the user can choose a supported application of their choice (e.g. Adobe Acrobat Reader). Cordova doesn't have an out-of-the-box solution to open intents in a general sense. A cordova plugin will need to expose a way to request for the PDF to be opened using an app capable of reading PDFs. Alternatively, Mozilla as a PDF reader implementation in pure JS using an HTML canvas (https://mozilla.github.io/pdf.js/). This will likely be not very performant if I were to guess, but it could be good enough for your needs and probably worth looking into. The getDocument API supports data types like an ArrayBuffer so you'd just use the cordova file plugin to read the data as an function readBinaryFile(fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function() {
let data = this.result; // This is the ArrayBuffer
};
reader.readAsArrayBuffer(file);
}, onErrorReadFile);
} |
Beta Was this translation helpful? Give feedback.
PDFs are complex binaries, so a pdf viewer software is necessary.
The proper "android" way is to use an Intent to open the PDF document, which the user can choose a supported application of their choice (e.g. Adobe Acrobat Reader).
Cordova doesn't have an out-of-the-box solution to open intents in a general sense. A cordova plugin will need to expose a way to request for the PDF to be opened using an app capable of reading PDFs.
Alternatively, Mozilla as a PDF reader implementation in pure JS using an HTML canvas (https://mozilla.github.io/pdf.js/). This will likely be not very performant if I were to guess, but it could be good enough for your needs and probably worth looking into. The g…