Búsqueda de sitios web

typescript - Cómo exportar una tabla dinámica a PDF en Angular 10


Quiero hacer un archivo PDF usando mi tabla dinámica existente. Ya lo intenté y el resultado será 50% exitoso. Uso jsPDF y el resultado será así

Quiero cambiar el ancho de la columna y también el texto del encabezado...

Componente.HTML

id="htmlData" #htmlData

Uso esto en mi div contenedor

Componente.TS

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import * as jsPDF from 'jspdf'
 @ViewChild('htmlData') htmlData: ElementRef;
    public openPDF():void {
    let DATA = this.htmlData.nativeElement;
    let doc = new jsPDF('l','pt', 'a4');
    doc.fromHTML(DATA.innerHTML,15,15,{
      'width':400,
      // autoSize:true,
    });
    doc.output('dataurlnewwindow');
  }

Respuesta #1

usar jsPDF-AutoTable - Plugin de tablas para jsPDF npm

jsPDF-AutoTable