PDF link only in browser

Im developing a PWA, yesterday I found other way to get the pdf using File-saver, you can try out, for me it was the solution.

here is my code to implement it.

import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import  * as FileSaver  from 'file-saver';

@Injectable()
export class FileServiceProvider {

  constructor() {
 
  }

  save(blob,fileName){
    FileSaver.saveAs(blob, fileName);
  }

}

when I call it.

download(value) {
    let blob = new Blob([this.s2ab(atob(value))], {
      type: TYPE_BLOB
    });
    this.file.save(blob, this.params.name + '.pdf');
  }

  s2ab(s) {
    var buf = new ArrayBuffer(s.length);
    var view = new Uint8Array(buf);
    for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
    return buf;
  }

the param called value is the pdf in BASE64.

cheers !!

1 Like