I followed a tutorial to create a resume in HTML/CSS/JS. The problem is to export this resume in pdf (actually one div): when I export it like in the video (with html2pdf.bundle.min.js) it transforms the page in the image than in pdf. But I want to keep the text selectable and really transform my HTML div into a pdf (text and layout).
Asked
Active
Viewed 948 times
0
-
Check this once https://stackoverflow.com/questions/18191893/generate-pdf-from-html-in-div-using-javascript – shweta ramani Jun 14 '21 at 07:15
-
"html2pdf.js renders all content into an image, then places that image into a PDF" therefore making it impossible to produce a PDF with selectable text. If i'm not mistaken PDF.js supports text selection so you may want to look into it. – kopz Jun 14 '21 at 07:15
1 Answers
1
Try This code :
HTML :
<h1>Book : A Brief History of Time</h1>
<h1>Writer : Stephen Hawking</h1>
<h1>Publisher : Bantam Books</h1>
<h1>Subject: Cosmology</h1>
<h1>Gener : Space</h1>
<button onclick="genPDF()">Generate PDF</button>
Script :
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script>
<script>
var elementHandler = {
'#ignorePDF': function (element, renderer) {
return true;
}
};
var source = window.document.getElementsByTagName("body")[0];
function genPDF() {
var doc = new jsPDF();
doc.fromHTML(
// print DOC Body to PDF file
source,
15,
15,
{
'width': 180,'elementHandlers': elementHandler
});
doc.save('Test.pdf');
}
</script>

Paramjot Singh
- 627
- 4
- 8