title: How can I get and view PDF (DocumentViewer) in Ionic 5?
body: <p>I follow a <a href="https://www.youtube.com/watch?v=k2iaGNApM9w" rel="nofollow noreferrer">YouTube video</a>  which guides on how to open PDF viewer. The assets folder contain the PDF is save under app folder which I try multiple file path (<code>let filePath = this.file.applicationDirectory + 'public/assets/';</code>) I'm also unable to make it work. The error logcat can be shown at bottom of this thread that output.</p>
  <p>HTML file</p>
  <pre><code>&lt;ion-button expand=&quot;full&quot; (click)=&quot;openLocalPdf()&quot;&gt;Open Local PDF&lt;/ion-button&gt;
  &lt;ion-button expand=&quot;full&quot; (click)=&quot;downloadAndOpenPdf()&quot;&gt;Download and open PDF&lt;/ion-button&gt;
  </code></pre>
  <p>Ts file</p>
  <pre><code>  openLocalPdf(){
              let filePath = this.file.applicationDirectory + 'public/assets/';
          
              if (this.platform.is('android')){
                let fakeName = Date.now //take file from this path inside app and copy it to another file location which can use native url top open and install previously
                this.file.copyFile(filePath,'sample.pdf', this.file.dataDirectory,`${fakeName}.pdf`).then(result =&gt;{
                  this.fileOpener.open(result.nativeURL, 'application/pdf');
                });
          
          
              } else {
                const options: DocumentViewerOptions ={
                  title: 'My PDF'
                }
                this.document.viewDocument(`${filePath}/sample.pdf`, `application/pdf`, options);
              }
            }
            
            downloadAndOpenPdf(){
              let downloadUrl = 'https://devdactic.com/html/5-simple-hacks-LBT.pdf';
              let path = this.file.dataDirectory;
              const transfer = this.ft.create();
          
              transfer.download(downloadUrl, `${path}myfile.pdf`).then(entry =&gt; {
                let url = entry.toURL();
                
                if (this.platform.is('ios')){
                  this.document.viewDocument(url,'application/pdf', {});
                } else {
                  this.fileOpener.open(url, 'application/pdf')
                }
              })
            }
  </code></pre>
  <blockquote>
  <ul>
  <li>2021-06-15 17:06:10.742 8228-8476/io.ionic.starter V/Capacitor/Plugin:<br />
    To native (Cordova plugin): callbackId: File79163689, service: File,
  action: resolveLocalFileSystemURI, actionArgs:<br />
  [&quot;file:///android_asset/public/assets/&quot;]</li>
  <li>2021-06-15 17:06:10.758 8228-8476/io.ionic.starter V/Capacitor/Plugin:<br />
    To native (Cordova plugin): callbackId:
  File79163690, service: File, action: requestAllFileSystems,
  actionArgs: []</li>
  <li>2021-06-15 17:06:11.277 8228-8476/io.ionic.starter V/Capacitor/Plugin:<br />
    To native (Cordova plugin): callbackId:
  File79163691, service: File, action: getFile, actionArgs:
  [&quot;cdvfile://localhost/assets/public/assets/&quot;,&quot;sample.pdf&quot;,{&quot;create&quot;:false}]</li>
  <li>2021-06-15 17:06:11.304 8228-8228/io.ionic.starter E/Capacitor/Console:<br />
    File: http://localhost/vendor.js - Line 60104 -
  Msg: ERROR</li>
  <li>2021-06-15 17:06:18.941 8228-8476/io.ionic.starter V/Capacitor/Plugin:<br />
    To native (Cordova plugin): callbackId:
  FileTransfer79163692, service: FileTransfer, action: download,
  actionArgs:
  [&quot;https://devdactic.com/html/5-simple-hacks-LBT.pdf&quot;,&quot;file:///data/user/0/io.ionic.starter/files/myfile.pdf&quot;,null,1,null]</li>
  <li>2021-06-15 17:06:18.961 8228-8228/io.ionic.starter E/Capacitor/Console:<br />
    File: http://localhost/vendor.js - Line 60104 -
  Msg: ERROR</li>
  <li>2021-06-15 17:06:44.863 8228-8228/io.ionic.starter E/Capacitor/Console:<br />
    File: http://localhost/polyfills.js - Line 3306 -
  Msg: Unhandled Promise rejection:</li>
  </ul>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/Hw6tr.png" rel="nofollow noreferrer">Error Shown in Android Studio Logcat</a></p>
  <p><a href="https://i.stack.imgur.com/XyV61.png" rel="nofollow noreferrer">Error Shown in Android Studio Logcat(RightSide)</a></p>