I spent a lot of time looking for a good representation of my tables, then I found this plugin (https://github.com/simonbengtsson/jsPDF-AutoTable), It works great, includes themes, rowspan, colspan, extract data from html, works with json, you can also personalize your headers and make them horizontals. The image below is an example:

Answer from Oscar Acevedo on Stack Overflow
🌐
GitHub
github.com › simonbengtsson › jsPDF-AutoTable
GitHub - simonbengtsson/jsPDF-AutoTable: jsPDF plugin for generating PDF tables with javascript
import { jsPDF } from 'jspdf' import { autoTable } from 'jspdf-autotable' const doc = new jsPDF() // It can parse html: // <table id="my-table"><!-- ... --></table> autoTable(doc, { html: '#my-table' }) // Or use javascript directly: autoTable(doc, { head: [['Name', 'Email', 'Country']], body: [ ['David', '[email protected]', 'Sweden'], ['Castille', '[email protected]', 'Spain'], // ... ], }) doc.save('table.pdf')
Starred by 2.5K users
Forked by 637 users
Languages   TypeScript 89.5% | HTML 7.6% | JavaScript 2.9%
🌐
npm
npmjs.com › package › jspdf-autotable
jspdf-autotable - npm
import { jsPDF } from 'jspdf' import { autoTable } from 'jspdf-autotable' const doc = new jsPDF() // It can parse html: // <table id="my-table"><!-- ... --></table> autoTable(doc, { html: '#my-table' }) // Or use javascript directly: autoTable(doc, { head: [['Name', 'Email', 'Country']], body: [ ['David', '[email protected]', 'Sweden'], ['Castille', '[email protected]', 'Spain'], // ... ], }) doc.save('table.pdf')
      » npm install jspdf-autotable
    
Published   Feb 26, 2025
Version   5.0.2
Author   Simon Bengtsson
🌐
Phppot
phppot.com › javascript › jspdf-autotable
jsPDF AutoTable example – Table to PDF - Phppot
PDF tables generation from HTML or JavaScript array using jsPDF AutoTables plugin.
🌐
Medium
medium.com › @charkins.dev › build-a-custom-table-with-react-jspdf-7d43729f6d70
Build a custom table with React/jsPDF | by Cory Harkins | Medium
January 29, 2020 - Hello, and welcome to my blog tutorial ... a custom table and export it using jsPDF! This tutorial aims to give you a better sense of the library and the powerful customization opportunities of jsPDF. There are already plug-ins for tabular structures offered by jsPDF; however, you may want more control and complete customization. I will be using React as my Javascript library of choice; however, the code is framework agnostic as we will be creating a pdf function that ...
🌐
Appsmith
community.appsmith.com › tutorial › data-driven-pdf-generator-jspdf-and-autotable
Data-Driven PDF Generator with JSPDF and Autotable | Appsmith Community Portal
October 12, 2024 - In this guide, we'll be using the JSPDF library and the JSPDF-AutoTable plug-in to generate PDFs from customer order data. This method builds a PDF programmatically, one line at a time, as opposed to other methods that use a template or HTML.
🌐
YouTube
youtube.com › watch
How to Add Tables to PDF Document Using jsPdf Autotable Library in Javascript - YouTube
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
Published   February 4, 2020
🌐
CSS Script
cssscript.com › home › categories › table › generate professional & beautiful pdf tables with jspdf-table
Generate Professional & Beautiful PDF Tables with jsPDF-Table | CSS Script
July 31, 2025 - A JavaScript library that helps you create feature-rich PDF tables with column alignment, text wrapping, custom styling, and professional themes.
Find elsewhere
Top answer
1 of 4
49

Here is working example:

in head

<script type="text/javascript" src="jspdf.debug.js"></script>

script:

<script type="text/javascript">
        function demoFromHTML() {
            var pdf = new jsPDF('p', 'pt', 'letter');
            // source can be HTML-formatted string, or a reference
            // to an actual DOM element from which the text will be scraped.
            source = $('#customers')[0];

            // we support special element handlers. Register them with jQuery-style 
            // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
            // There is no support for any other type of selectors 
            // (class, of compound) at this time.
            specialElementHandlers = {
                // element with id of "bypass" - jQuery style selector
                '#bypassme': function(element, renderer) {
                    // true = "handled elsewhere, bypass text extraction"
                    return true
                }
            };
            margins = {
                top: 80,
                bottom: 60,
                left: 40,
                width: 522
            };
            // all coords and widths are in jsPDF instance's declared units
            // 'inches' in this case
            pdf.fromHTML(
                    source, // HTML string or DOM elem ref.
                    margins.left, // x coord
                    margins.top, {// y coord
                        'width': margins.width, // max width of content on PDF
                        'elementHandlers': specialElementHandlers
                    },
            function(dispose) {
                // dispose: object with X, Y of the last line add to the PDF 
                //          this allow the insertion of new lines after html
                pdf.save('Test.pdf');
            }
            , margins);
        }
    </script>

and table:

<div id="customers">
        <table id="tab_customers" class="table table-striped" >
            <colgroup>
                <col width="20%">
                <col width="20%">
                <col width="20%">
                <col width="20%">
            </colgroup>
            <thead>         
                <tr class='warning'>
                    <th>Country</th>
                    <th>Population</th>
                    <th>Date</th>
                    <th>Age</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Chinna</td>
                    <td>1,363,480,000</td>
                    <td>March 24, 2014</td>
                    <td>19.1</td>
                </tr>
                <tr>
                    <td>India</td>
                    <td>1,241,900,000</td>
                    <td>March 24, 2014</td>
                    <td>17.4</td>
                </tr>
                <tr>
                    <td>United States</td>
                    <td>317,746,000</td>
                    <td>March 24, 2014</td>
                    <td>4.44</td>
                </tr>
                <tr>
                    <td>Indonesia</td>
                    <td>249,866,000</td>
                    <td>July 1, 2013</td>
                    <td>3.49</td>
                </tr>
                <tr>
                    <td>Brazil</td>
                    <td>201,032,714</td>
                    <td>July 1, 2013</td>
                    <td>2.81</td>
                </tr>
            </tbody>
        </table> 
    </div>

and button to run:

<button onclick="javascript:demoFromHTML()">PDF</button>

and working example online:

tabel to pdf jspdf

or try this: HTML Table Export

2 of 4
21

You can also use the jsPDF-AutoTable plugin. You can check out a demo here that uses the following code.

const doc = new jsPDF();
autoTable(doc, "#basic-table");
doc.save("table.pdf");
🌐
CodePen
codepen.io › CJHARKINS › pen › JmjxvG
jsPDF table
const verticalOffset = margin; var columns = [ {title: "COL1", dataKey: "col1"}, {title: "COL2", dataKey: "col2"}, {title: "COL3", dataKey: "col3"}, {title: "COL4", dataKey: "col4"} ]; var rows = [ { "col1": status, "col2": `${data1}\n${data2}`, "col3": creator, "col4": date.getUTCDate() }, { "col1": "data-cell_r2_c1", "col2": "data-cell_r2_c2", "col3": "data-cell3_r2_c3", "col4": "data-cell4_r2_c4" }, { "col1": "data-cell_r3_c1", "col2": "data-cell_r3_c2", "col3": "data-cell3_r3_c3", "col4": "data-cell4_r3_c4" } ]; btn.addEventListener("click", () => { const name = input.value; doc.autoTable(
🌐
Plunker
embed.plnkr.co › enTDfltWHNZ6NjjCjkSA
jsPDF table example - Plunker
body{ background-color:#FF0; } button { cursor: pointer; } table{ padding: 50px; position:absolute; left:50%; -webkit-transform: translateX(-50%); -moz-transform: translateX(-50%); transform: translateX(-50%);; background-color:'#FF0'; } #pdfTable th{ background-color:'#FAA'; } /** @preserve * jsPDF - PDF Document creation from JavaScript * Version 1.0.272-git Built on 2014-09-29T15:09 * CommitID d4770725ca * * Copyright (c) 2010-2014 James Hall, https://github.com/MrRio/jsPDF * 2010 Aaron Spike, https://github.com/acspike * 2012 Willow Systems Corporation, willow-systems.com * 2012 Pablo Hess
🌐
MIT App Inventor
community.appinventor.mit.edu › mit app inventor help
Generate a pdf table with the jspdf library - MIT App Inventor Help - MIT App Inventor Community
January 20, 2020 - i managed to make simple pdf pages with some text and images on the “page”, but now comes the hard thing. I stored some data in a tiny_db asset and whanna make a grid on the paper. I see this example code on the jspdf page, but do not know how to handle those “vectors” to pass to the pdf generation code … lists?: var generateData = function (amount) { var result = []; var data = { coin: "100", game_group: "GameGroup", game_name: "XPTO2", game_version: "25", machine: "20485...
🌐
Medium
medium.com › @aalam-info-solutions-llp › creating-dynamic-pdfs-with-jspdf-and-customizing-autotables-in-react-a846a6f3fdca
Creating Dynamic PDFs with JsPDF and Customizing AutoTables in React | by Aalam Info Solutions LLP | Medium
March 6, 2024 - pdf.autoTable: This function is provided by the jsPDF-AutoTable library. It automatically generates a table based on the provided data and settings.
🌐
UNPKG
unpkg.com [email protected] › README.md
Unpkg
# jsPDF-AutoTable - Table plugin for jsPDF **Generate PDF tables with Javascript** This jsPDF plugin adds the ability to generate PDF tables either by parsing HTML tables or by using Javascript data directly. Check out the [demo](https://simonbengtsson.github.io/jsPDF-AutoTable/) or ...
🌐
Simonbengtsson
simonbengtsson.github.io › jsPDF-AutoTable
AutoTable sample
It appears you don't have PDF support in this web browser. Click here to download the PDF
🌐
CodeSandbox
codesandbox.io › examples › package › jspdf-autotable
jspdf-autotable examples - CodeSandbox
pdf-with-react-and-jspdf-forked · material-react-table-example-export-to-csv · surveyjs_react_quickstart · attendance-management-project · react-table-with-fakestore-api · surveyjs-vue-quickstart · antd-export-tableExport ant.design tables as Excel, CSV and PDF ·
🌐
TheoryApp
theoryapp.com › how-to-create-a-table-using-jspdf
How to Create a Table using jsPDF – TheoryApp
July 9, 2023 - By executing this code, a PDF document with a simple table will be generated and saved as “table.pdf”. The table will display the provided data with the specified columns and rows. You can modify the columns, rows, and table options to fit your specific requirements. To add the jspdf-autotable ...
🌐
GitHub
github.com › JonatanPe › jsPDF-AutoTable
GitHub - JonatanPe/jsPDF-AutoTable
cursor - The position at which the next table cell will be drawn. This can be assigned new values to create column and row spans. Checkout the Colspan and Rowspan example for more information. OBS! Only the drawCell hook can be used with the native style jspdf style changes such as doc.setLineWidth.
Starred by 17 users
Forked by 4 users
Languages   TypeScript 81.5% | JavaScript 18.5%
🌐
GitHub
github.com › Walah › ConvertSingleOrMultipleTableToPDF
GitHub - Walah/ConvertSingleOrMultipleTableToPDF: This example converts (single or multiple) HTML table(s) to PDF using the jsPDF autotable plugin
This example converts (single or multiple) HTML table(s) to PDF using the jsPDF autotable plugin - Walah/ConvertSingleOrMultipleTableToPDF
Author   Walah