简体   繁体   中英

Angular open a pdf in new tab

In my angular 12 application I want to "view" a pdf file in a new chrome tab. The file is saved locally in the application and we need a functionality where user can view the pdf in a new tab ( not just download ). I am handling this in HTML like this:

<a [href]="privacyLinks.pdfLink" (click)="previewPdf(privacyLinks.pdfLink)"  class="policy-control-link"
target="_blank"><img [src]="privacyLinks.viewSvg" alt="">{{
privacyLinks.viewLabel }}

This is downloading the file instead of opening it a new tab. I tried creating a (click) function and use window.open(pdfFile,'_blank') but it still does the same thing. How do I open the.pdf in a new Chrome tab?

Function that retrieves pdf and opens in new tab. Works with Chrome

  onCreateInvoice(params: Params) {
     this.http.post(this.path, params, { responseType: 'blob' })
       .subscribe(somePdf => {
          window.open(URL.createObjectURL(somePdf), 'new');
       })
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM