title: Download and view pdf using Cordova plugins and Ionic 3 not working
body: <p>Hello I am facing an issue while trying to open a pdf on mobile devices, using ionic 3. Basically I get the pdf from a web service and after decrypting the file, I ask if is being opened from a browser or from an application. If is being opened from the browser, I use in app browser to render pdf and it works like a charm, no problems there, but when is opened from a mobile device like an App I take a different approach, download the file and open it using </p>
  
  <blockquote>
    <p>Document Viewer plugin
    File
    File Transfer</p>
  </blockquote>
  
  <p>here is some code, first we make the call to the web service and subscribe to the response:</p>
  
  <pre><code>clickBtn(e) {
   const loading = this.loadingController.create({
     content: ''
  });
  loading.present().then(() =&gt; {
    const productExtractsRq: ProductExtractsRq = this.extractRq;
    productExtractsRq.customer = this.bdbUtilsProvider.getCustomer();
    // get file from WEB SERVICE
    this.transactionsProvider.getProductExtracts(productExtractsRq).subscribe(
      (data) =&gt; {
        loading.dismiss();
        // CREATE THE PDF
        this.blob = this.createPdf(data);
        this.url = window.URL.createObjectURL(this.blob);
        // COMPARE WHICH PLATFORM IS ACCESSING THE APP
        if (this.platform.is('core') || this.platform.is('mobileweb')) {
          this.iab.create(this.url, '_system');
        } else {
          this.downloadAndOpenPdf(this.url);
        }
      },
      (ex) =&gt; {
        loading.dismiss();
        if (ex.status === 409) {
          this.tsErrorProvider.launchErrorModal(ex.error._error);
        } else {
          this.bdbModal.launchErrModal(
            'Ha ocurrido un error',
            'El extracto no se pudo generar, por favor intenta más tarde.',
            'Aceptar'
          );
        }
      }
    );
  });
  }
  </code></pre>
  
  <p>here is the method for when is opened by app:</p>
  
  <pre><code>downloadAndOpenPdf(url: string) {
  let path = null;
  
  if (this.platform.is('ios')) {
    path = this.file.documentsDirectory;
  } else if (this.platform.is('android')) {
    path = this.file.dataDirectory;
  }
  
  // this.document.viewDocument(url, 'application/pdf', {});
  
  const transfer = this.transfer.create();
  transfer.download(url, path + 'myfile.pdf').then(entry =&gt; {
    toast.present();
    const _url = entry.toURL();
    this.document.viewDocument(_url, 'application/pdf', {});
  })
  .catch(err =&gt; {
    alert(JSON.stringify(err));
    toast.present();
    this.iab.create(url, '_blank');
  });
  }
  </code></pre>
  
  <p>and here is the create pdf method, which apparently works fine.</p>
  
  <pre><code>createPdf&lt;Blob&gt;(data: ProductExtractsRs) {
  const bytes: string = atob(atob(data.binData));
  const byteNumbers = new Array(bytes.length);
  for (let i = 0; i &lt; bytes.length; i++) {
    byteNumbers[i] = bytes.charCodeAt(i);
  }
  const byteArray = new Uint8Array(byteNumbers);
  return new Blob([byteArray], { type: 'application/pdf' });
  }
  </code></pre>
  
  <p>So whenever I try to open the pdf I get the error:</p>
  
  <pre><code>{
   "code":2,
   "source":"blob:file:///a44e17fc-1eb7-458a-9130-3d7b4f3a790b",
   "target": "file///data/user/0/io.ionic.starter/files/myfile.pdf",
   "http_status":null,
   "body": null,
   "exception": null
  }
  </code></pre>
  
  <p>And nothing else happens, anyone can tell what am I doing wrong?, remember that the pdf opens with no problem using the in app browser on web app. Any hint will be highly appreciated !</p>