on-internet
← Community

Print PDF in new browser tab

Stack Overflow ·

I have this two pieces of code that works today: This one gets a blob file I retrieved from backend and open a 'print dialog' on current tab: var blob = new Blob([response.body], {type: 'application/pdf'}); const blobUrl = URL.createObjectURL(blob); const iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = blobUrl; document.body.appendChild(iframe); iframe.contentWindow.print(); This one opens a new tab to download a file (which is returned as inline by the server): var form = document.createElement("form"); form.target = "_blank"; form.method = method; form.

Comments

Sign in or sign up to comment and upvote.

No comments yet.