title: Silently print a PDF file using javascript
body: <p>The thing I want to build is that by clicking a button I want to trigger the direct print of a PDF file, but without opening or viewing it.</p>
  
  <p>I have PDF as blob file returned from fetch API. </p>
  
  <p>I tried a lot of examples but don't know exactly how to do it</p>
  
  <p>Some examples tried:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// In my case, I had only blobData from PDF, but you can ignore this and set fileURL directly if it is not yours.
  const file = new Blob([blobData], { type: 'application/pdf' });
  const fileURL = window.URL.createObjectURL(file);
  
  // As the URL is dynamic, we must set src here, but if it's not, just leave it direct on the HTML. 
  // Also, be careful with React literals. If you do this in a &lt;iframe&gt; defined in JSX, it won't work 
  // as React will keep src property undefined.
  window.frames["my-frame"].src = fileURL;
  
  // Then print:
  window.frames["my-frame"].print();</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;iframe name="my-frame" id="my-frame" title="my-frame" style="display: none"&gt;&lt;/iframe&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Also tried library, Print.js: <a href="http://printjs.crabbly.com/" rel="noreferrer">http://printjs.crabbly.com/</a>.</p>
  
  <p>Is there way to print the pdf without visually opening it to the user?
  We should support only Chrome browser.</p>
  
  <p>Can someone provide example how to do it in React, Redux application?</p>