JSFiddle - React, Tailwind, and code Playground

by Rapha Souza

HTML

<script src="https://code.jquery.com/jquery-3.4.1.slim.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css">
<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jspdf encode pdf to base64 code</title>
  </head>

  <body>
    <div class="zima">
<div class="A4 col-md-12" id="area_printer">
      <div class="page_header"> <img src="https://poc.fluig.com:8084/volume/stream/Rmx1aWc=/P3Q9MSZ2b2w9RGVmYXVsdCZpZD02Mjg0JnZlcj0xMDAwJmZpbGU9aW1hZ2VtXzIwMjMtMTEtMDlfMTIxNDU5Mzc3LnBuZyZjcmM9MzIzMDgyNTU2OCZzaXplPTAuMDEwNjQ5JnVJZD0xNCZmU0lkPTEmdVNJZD0xJmQ9ZmFsc2UmdGtuPSZwdWJsaWNVcmw9dHJ1ZQ==.png" width="150px"> </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="row"><br>
      </div>
      <div class="text-center" style="">
        <h3>RELATÓRIO DE CONFORMIDADE FISCAL</h3>
        <h3>ETAPA 0139 - CSC | DISPONIBILIDADE DA REDE COM ÁREA 15</h3>
        <h3>RT978/23</h3>
      </div>
    </div>
   ...

JavaScript

function getPDF() {
  var doc = new jsPDF();
 
  // We'll make our own renderer to skip this editor
  var specialElementHandlers = {
    '#getPDF': function(element, renderer){
      return true;
    },
    '.controls': function(element, renderer){
      return true;
    }
  };

  // All units are in the set measurement for the document
  // This can be changed to "pt" (points), "mm" (Default), "cm", "in"
  doc.fromHTML($('.zima').get(0), 15, 15, {
    'width': 170, 
    'elementHandlers': specialElementHandlers
  });

  doc.save('Generated.pdf');
}