Hello everyone, this is my first experience with Capacitor, I’m on a Vue.js application with pdf generation via pdfMake.
My problem is when in Android Studio, I try to download the pdf, it opens me the android message app.
Here is my code to generate the pdf :
const pdfFile = pdfMake.createPdf(docDefinition);
let pdfString = JSON.stringify(pdfFile);
let platform = Capacitor.getPlatform();
if (platform != "web") {
try {
Filesystem.writeFile({
path: nameFile,
data: pdfString,
directory: Directory.Documents,
encoding: Encoding.UTF8,
recursive: true
}).then(() => {
Filesystem.getUri({
directory: Directory.Documents,
path: nameFile,
}).then(
(getUriResult) => {
const path = getUriResult.uri.replace("file:","content:");
Browser.open({ url: `${path}.pdf` })
.then(() => console.log("File is opened"))
.catch((error) => console.log("Error openening file", error));
},
(error) => {
console.log(error);
}
);
});
} catch (error) {
console.error("Unable to write file", error);
}
}else{
pdfFile.download(`${nameFile}.pdf`);
}
Thank you for your help