Tuesday, November 3, 2015

Load PDF into iframe and call print

<html>
<head>
<script src="jquery-1.11.3.min.js"></script>
<script>
jQuery(document).ready(function($) {
  function print(url)
  {
      var _this = this,
          iframeId = 'iframeprint',
          $iframe = $('iframe#iframeprint');
      $iframe.attr('src', url);

      $iframe.load(function() {
          callPrint(iframeId);
      });
  }

  //initiates print once content has been loaded into iframe
  function callPrint(iframeId) {
      var PDF = document.getElementById(iframeId);
      PDF.focus();
      PDF.contentWindow.print();
  }

  print('http://mydomain.local/test.pdf');
});
</script>
</head>
<body>
  <iframe id="iframeprint"></iframe>
</body>
</html>

Reference:

http://www.sitepoint.com/load-pdf-iframe-call-print/

No comments: