'How to download PDF in ionic/capacitor/vue

I have pdf in blob:

data:application/pdf;base64,JVBERi0xL...

How do I view this pdf file in InAppBrowser or download and view it in Chrome in Android platform? Thanks.



Solution 1:[1]

You just need to create a <a> tag and then trigger the download:

const data = 'data:application/pdf;base64,JVBERi0xL...';

const downloadPDF = (href) => {
  const downloadLink = document.createElement("a");
  downloadLink.href = href;
  downloadLink.download = "fileName.pdf";
  downloadLink.click();
};

downloadPDF(data);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RGe