-1

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).

2
  • Check this once stackoverflow.com/questions/18191893/… Commented Jun 14, 2021 at 7: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. Commented Jun 14, 2021 at 7:15

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

For those coming here from 2024 onwards, the fromHTML method no longer exists.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.