Search code examples
ionic5pdftron

ionic 5 PDFTron Webviewer doesn't have access to file URLs because of browser security restrictions


I try to integrate the PDFTron API in an ionic 5 application in which I download the pdf from the server, store them on the phone and then open them with the API currently when I put the files in the assets folder of my ionic project, the api opens it without problem but when I download the file to the phone memory and try to open it with the API by passing the link of this file, I have the following error (on the image)

enter image description here

Is there a way to fix this or store the downloaded files in the assets folder?


Solution

  • for those who encounter this same problem, just convert the native url (Ex file: ///storage/emulated/0/USL/20.PDF) into a url that the webviewer accepts using this:

    let safeURL = win .Ionic.WebView.convertFileSrc (your native url);
    

    you can also follow this link: where was file location downloaded in Ionic