Print PDF directly from JavaScript

Woocoders
Woocoders
23rd August 2023
Print PDF directly from JavaScript
				
					  function printFile(url) {
    const iframe = document.createElement('iframe');
    iframe.src = url;
    iframe.style.display = 'none';
    document.body.appendChild(iframe);

    // Use onload to make pdf preview work on firefox
    iframe.onload = () => {
       iframe.contentWindow.focus();
       iframe.contentWindow.print();
    };
  }
				
			

Share this post: