1

I have received a PDF from a server in which the user often wants to print without really looking at it. I try to use an onafterprint event to close the window, however, it foes not seem to get triggered when I open a PDF this way. If I instead set the URL blank to open an empty page it seems to work just fine.

let url = URL.createObjectURL(blob);
let printWindow = window.open(url);
printWindow.onafterprint = function(){
  console.log("afterprint")
};
Denis Tsoi
  • 9,428
  • 8
  • 37
  • 56
OBro
  • 11
  • 1

1 Answers1

1

Your code won't get executed since the pdf window MIME type is "application/pdf", not "text/html".

Check this one for more details. https://stackoverflow.com/a/51735450/1141936

ImLeo
  • 991
  • 10
  • 17