JSFiddle - React, Tailwind, and code Playground
by Rapha Souza
HTML
<!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>encode pdf file to base64 data url in html2pdf.js</title>
</head>
<body>
<div id="root">
<h1>This is a heading</h1>
<p>This is a paragraph</p>
<a href="https://google.com">Google</a>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js" integrity="sha512-GsLlZN/3F2ErC5ifS5QtgpiJtWd43JWSuIgh7mbzZ8zBps+dvLusV+eNQATqgA/HdeKFVgA5v3S/cIrLF7QnIg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
html2pdf().from(document.getElementById('root')).outputPdf().then((url) => {
alert(btoa(url))
let base64 = btoa(url)
})
</script>
</html>