Skip to content

This example converts (single or multiple) HTML table(s) to PDF using the jsPDF autotable plugin

Notifications You must be signed in to change notification settings

Walah/ConvertSingleOrMultipleTableToPDF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Convert Single or Multiple Table to PDF

For one of my projects, I had to export HTML table to a PDF file with

  • page title
  • table
  • table header
  • disclaimer footnote

Eventually the following requirements came along:

  • not all the single table will have table header
  • need to export multiple tables with their headers
  • a few tables might need to be exported in landscape page orientation
  • all the tables have specific names, so the PDF file should use that name

After some googling I found out that the jsPDF autotable plugin will be the easiest way to achieve my goals.

In my example, the convertTableToPDF() has the following parameters:

  • {string} fileName - the name of the PDF file
  • {string} title - ID of the page title (and sub-title) section (optional, but have to send an empty string; like '' )
  • {string[]} tableArray - ID(s) of the HTML table(s)
  • {string[]} tableHeaderArray - ID(s) of the HTML table header(s) (for single table with no table header, this can be left blank; like [])
  • {string} pg_orientation - preferred printing page orientation (optional, can be omitted)

Feel free to use and modify this solution as needed. I do understand that there are a lot of ways to improve this function, but this was the quickest solution I could come up with for my project (for now). For example, I'm not happy the way I had to create different table options for each of my tables, would appreciate if someone can come up with a better solution :)

About

This example converts (single or multiple) HTML table(s) to PDF using the jsPDF autotable plugin

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published