3

I am generating a .pdf in ASP.NET MVC and sending it to Angular 5 service. The requirement is to have it opened in new tab without downloading.

When the .pdf is generated, I send it to front end as a FileResult conatining a byte array and "application/pdf" content type.

This answer pointed me to the following solution:

getPdf(): void {  
    let newTab = window.open(); //opens new tab immediately to avoid popup blocking 

    this.pdfService.getPdf().subscribe(res => {

      var fileURL = URL.createObjectURL(res); //Blob from the backend
      newTab.location.href = fileURL;
    });
  }

This solution works on Chrome and Mozilla, but not in Edge. When I try the functionality in Edge, the tab that is opened never shows the content. Furthermore, I get the following error in console:

[object Error]: {description: "Permission denied", message: "Permission denied", number: -2146828218, stack: "Error: Permission denied at Anonymous function (eval code:312:13) at SafeSubscriber.prototype.__tryOrUnsub (eval code:244:13) at SafeSubscriber.prototype.next (eval code:191:17) at Subscriber.prototype._next (eval code:132:9) at Subscriber.prototype.next (eval code:96:13) at MapSubscriber.prototype._next (eval code:88:9) at Subscriber.prototype.next (eval code:96:13) at FilterSubscriber.prototype._next (eval code:92:13) at Subscriber.prototype.next (eval code:96:13) at MergeMapSubscriber.prototype.notifyNext (eval code:156:13)"}

dzenesiz
  • 1,388
  • 4
  • 27
  • 58

0 Answers0