JSFiddle - React, Tailwind, and code Playground

by Alex

HTML

<script src="https://f.cl.ly/items/0P2H1B0H0B1E1w2C2q2K/jspdf.debug.js"></script>
<script src="https://f.cl.ly/items/3I0q1s2l1l0n1V3X100F/svg.js"></script>




<iframe></iframe>

CSS

iframe {
  margin: auto;
  width: 99%;
  height: 95vh;
  border: 1px solid #f00;
}

JavaScript

document.onreadystatechange = function() {

  var doc = new jsPDF();
  doc.text(20, 20, 'This PDF has a title, subject, author, keywords and a creator.');
  doc.text(20, 40, 'This PDF has a title, subject, author, keywords and a creator.');
  doc.text(20, 60, 'This PDF has a title, subject, author, keywords and a creator.');

  var pdfURI = "";
  pdfURI = doc.output('datauristring');
  //pdfURI = doc.output('bloburi');
  //document.getElementByTagName('iframe')[0].src = pdfURI;
  console.log(pdfURI);

  /*
  document.body.removeChild(                
    document.getElementsByTagName('iframe')[0]
  );
  var iframe = document.createElement('iframe');
  iframe.src=pdfURI;
  document.body.appendChild(iframe);
  */
  document.location.href = pdfURI;
}