How to preview a base64 PDF with ionic capacitor

Viewed 333

I am trying to open and preview a PDF from a capacitor application.

Here is my code :

const { Browser } = Plugins;
let base64Pdf = "";
var contentType = "application/pdf";
var dataBlob = this.b64toBlob(base64Pdf, contentType);
await Browser.open({ url: URL.createObjectURL(dataBlob) }).then(() => {
    console.log("PDF OK");
}).catch(err => {
    console.log(err);
})

This is working great on web, but does not work on iOS. I get an error saying that the URL is invalid. I also tried to use

window.open(URL.createObjectURL(dataBlob), '_blank');

and

window.open(URL.createObjectURL(dataBlob), '_system');

But none of these work. I do not get any error output.

When using self, the PDF is opening well, but since it opens inside the webview, there is no more control and the user is stuck :

window.open(URL.createObjectURL(dataBlob), '_system');

enter image description here

Thanks in advance for any help

0 Answers
Related