Andreea Popa
Andreea Popa

Reputation: 49

Angular jspdf export PDF formatting

I have a table that i want to export. It looks something like this: enter image description here

This is the function:

    public downloadAsPDF() {
      const doc = new jsPDF();

      const specialElementHandlers = {
        '#editor': function (element, renderer) {
          return true;
        }
      };

      const pdfTable = this.pdfTable.nativeElement;

      doc.fromHTML(pdfTable.innerHTML, 15, 15, {
        width: 190,
        'elementHandlers': specialElementHandlers
      });

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

My problem is that when i export, it looks like this (It doesn't respect the formatting, the spaces):

enter image description here

Is there something i can do or this is normal? Thank you!

Upvotes: 0

Views: 1129

Answers (1)

Quentin Grisel
Quentin Grisel

Reputation: 4987

JSPDF only take care of exporting your html code if I remember well. If you don't need to interact with your pdf, then you could use html2pdf. It uses jspdf and html2canvas to convert the given block of code into an image and then paste it in a pdf file.

here is a short video explaining how it works.

Upvotes: 1

Related Questions