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
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 or examples.
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
To see what is included in the Table, Row, Column and Cell types, either log them to the console or take a look at src/models.ts · // Example with an image drawn in each cell in the first column autoTable(doc, { didDrawCell: (data) => { if (data.section === 'body' && data.column.index === 0) { const base64Img = 'data:image/jpeg;base64,iVBORw0KGgoAAAANS...' doc.addImage(base64Img, 'JPEG', data.cell.x + 2, data.cell.y + 2, 10, 10) } }, }) ... jsPDF.autoTableSetDefaults({ /* ...
      » 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 - We are setting the orientation ... point (jsPDF offers mm, in, and px as valid measurements), and the paper size format is a4 in this example. Now, we know that our paper size is A4, however, what does that really mean in context of our unit of measurement? We need to get the page dimensions in height and width based in Point sizes. In the source code here, there is a table that represents ...
🌐
CodePen
codepen.io › CJHARKINS › pen › JmjxvG
jsPDF table
const doc = new jsPDF({ orientation: "p", //set orientation unit: "pt", //set unit for document format: "letter" //set document standard }); const btn = document.querySelector("button"); const input = document.querySelector("input"); const data1 = 'Type/Type', data2 = 'asidghalwkghuahewlgauhlwegnva', status = 'STATUS', creator = 'James Dean', date = new Date(); const sizes = { xs: 10, sm : 14, p: 16, h3: 18, h2: 20, h1: 22 }; const fonts = { times: 'Times', helvetica: 'Helvetica' }; const margin = 0.5; // inches on a 8.5 x 11 inch sheet.
🌐
Plunker
embed.plnkr.co › enTDfltWHNZ6NjjCjkSA
jsPDF table example - Plunker
var app = angular.module('angularjs-starter', ['ui.bootstrap']); app.controller('MainCtrl', function($scope) { $scope.savePDF = function(){ var pdf = new jsPDF('p','pt','a4'); //var source = document.getElementById('table-container').innerHTML; console.log(document.getElementById('table-container')); var margins = { top: 25, bottom: 60, left: 20, width: 522 }; // all coords and widths are in jsPDF instance's declared units // 'inches' in this case pdf.text(20, 20, 'Hello world.'); pdf.addHTML(document.body, margins.top, margins.left, {}, function() { pdf.save('test.pdf'); }); }; $scope.data =
🌐
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
Find elsewhere
🌐
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 - You can modify the columns, rows, and table options to fit your specific requirements. To add the jspdf-autotable library to your JavaScript project, you need to include the library script file in your HTML file. Here’s an example of the complete JavaScript code that includes the jspdf-autotable ...
🌐
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 - See the JSPDF docs for more details and other methods. Run the function and you should get back a DataUrl. This is a base64 representation of the file, and can be used in place of a URL to display the PDF in a DocumentViewer widget. For more info on DataUrls and Base64, check out this post. ... The PDF should now be displaying in the DocumentViewer. Next, we need some sample data to display in a table on the PDF. For this example, we'll be using hard-coded sample data, but you can swap this out for your own datasource as needed.
🌐
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
🌐
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 see this example code on the ... code … lists?: var generateData = function (amount) { var result = []; var data = { coin: "100", game_group: "GameGroup", game_name: "XPTO2", game_version: "25", machine: "20485......
🌐
UNPKG
unpkg.com [email protected] › README.md
Unpkg
For example the position on the page, which page it is on etc. `HookData`: - `table: Table` - `pageNumber: number` The page number specific to this table - `settings: object` Parsed user supplied options - `doc` The jsPDF document instance of this table - `cursor: { x: number, y: number }` ...
🌐
CodePen
codepen.io › someatoms › pen › adojWy
Two tables and header with jspdf-autotable
<td>Nichols</td> <td>[email protected]</td> <td>Canada</td> <td>18.186.38.37</td> </tr> </tbody> </table> ... function generate() { var doc = new jsPDF('p', 'pt'); var res = doc.autoTableHtmlToJson(document.getElementById("basic-table")); ...
🌐
jsDocs.io
jsdocs.io › package › jspdf-autotable
[email protected] - jsDocs.io
Called after a cell has been added to the page. Can be used to draw additional cell content such as images with doc.addImage, additional text with doc.addText or other jspdf shapes.
🌐
GitHub
github.com › parallax › jsPDF › blob › master › examples › html2pdf › tables.html
jsPDF/examples/html2pdf/tables.html at master · parallax/jsPDF
Client-side JavaScript PDF generation for everyone. - jsPDF/examples/html2pdf/tables.html at master · parallax/jsPDF
Author   parallax
🌐
C# Corner
c-sharpcorner.com › article › export-an-html-table-using-jspdf-autotable
Export An HTML Table To PDF Using jsPDF - Autotable
October 4, 2020 - In this article, you will learn how to export an HTML table to PDF using jsPDF - autotable.
🌐
Pdfnoodle
pdfnoodle.com › blog › generating-pdfs-from-html-with-jspdf
Generating PDFs from HTML with jsPDF and javascript
January 30, 2025 - Below are some jsPDF examples to ... plugin for structured data: doc.autoTable({ head: [['Name', 'Email']], body: [['Alice', '[email protected]'], ['Bob', '[email protected]']], }); Adding pages: Multiple page documents ...
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");