0

I have a base64 pdf on client side, I want to open the print dialog on same tab in browser but could not find a way to do it.

I explored some answers like window.open() but it opens print dialog in another tab

Can somebody tell me how to achieve this?

jps
  • 20,041
  • 15
  • 75
  • 79
Srushti Shah
  • 810
  • 3
  • 17
  • 2
    `window.print()`? It's unclear how the pdf is related to the print requirement / how the pdf is loaded/displayed. Tell users to press ctrl+p? Or alt-f-p? – freedomn-m Sep 14 '22 at 05:45
  • It will print the whole page, but I want to print the pdf on click of button that is not present on the page – Srushti Shah Sep 14 '22 at 06:40
  • 1
    You want to print something that's not on the page? Where exactly is the PDF? Can't users view the PDF and click the PDFs print button? Did you want to *force* print? ie not give the user the option to print but just print it? – freedomn-m Sep 14 '22 at 06:45
  • I have a page where I show the details of a specific order, now I have 2 buttons - download and print invoice for the same order, so on print button, I generate invoice and make a pdf, to send it on the client side, I am converting it to base64, so now I want to print that base64 pdf – Srushti Shah Sep 14 '22 at 06:52
  • Numerous, different solutions on this answer: https://stackoverflow.com/questions/2255291/print-the-contents-of-a-div – freedomn-m Sep 14 '22 at 06:57

1 Answers1

0

You can use print-js library You only have to pass base64 pdf and it will open the print popup by itself.

printJS({ printable: "your_base64_of_pdf", type: 'pdf' });