Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pdfMake - open() and print() functions are not working

I'm trying to learn how to use pdfMake. I'm trying to use open and print to generate or print the information respectively. But, when I click on the button which fires the event, a new tab opens for a second and vanishes. The page which opens is displayed in history as blob:http://localhost:9999/93c1600e-3c64-42fe-8b44-fe6eeb995b5e

I'm not able to figure out the error. I'm following the official documentation of pdfMake.

Please help.

function print(){
  window.event.preventDefault()
  // this is just a simulation of the open event, replacing it with print produces the same result
  var docDefinition = { content: {text:'This is an sample PDF printed with pdfMake',fontSize:15} };
  pdfMake.createPdf(docDefinition).open();
}
<!DOCTYPE HMTL>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1.0" />
  <script src='https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.27/pdfmake.min.js'></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.27/vfs_fonts.js"></script>
  <script src="js/print.js"></script>
</head>
<body>
  <main>
    <button onclick="print()">Print Card</button>
  </main>
</body>
</html>
like image 895
Ritik Saxena Avatar asked Apr 29 '17 06:04

Ritik Saxena


1 Answers

Please check that any type of ad blocker in your browser is turned off and try again.

like image 51
steffanjj Avatar answered Oct 08 '22 10:10

steffanjj