https://github.com/MrRio/jsPDF
英文文档 https://parall.ax/products/jspdf

  1. yarn add jspdf jspdf-autotable

jspdf-autotable表格自适应

  1. import jsPDF from 'jspdf'
  2. import 'jspdf-autotable'
  3. const doc = new jsPDF()
  4. // It can parse html:
  5. // <table id="my-table"><!-- ... --></table>
  6. doc.autoTable({ html: '#my-table' })
  7. // Or use javascript directly:
  8. doc.autoTable({
  9. head: [['Name', 'Email', 'Country']],
  10. body: [
  11. ['David', 'david@example.com', 'Sweden'],
  12. ['Castille', 'castille@example.com', 'Spain'],
  13. // ...
  14. ],
  15. })
  16. doc.save('table.pdf')