Table Width and jsPDF Font Size

I thought it would be relatively simple, but I can’t find the answer anywhere, I had a good hunt in stack overflow. Sorry if I missed something obvious!

How do you set table width in jsPDF? I just want my table to stretch to 100% of the page width. Here is the code I'm using:

<script> function demoFromHTML() { var pdf = new jsPDF('p', 'pt', 'a4'); source = $('#pdf')[0]; specialElementHandlers = { '#bypassme': function (element, renderer) { return true } }; margins = { top: 80, bottom: 40, left: 40, width: 600 }; pdf.fromHTML( source, margins.left, margins.top, { 'width': margins.width, 'elementHandlers': specialElementHandlers }, function (dispose) { pdf.output('datauri'); }, margins); } </script> 

I use a standard, unformatted HTML table.

 <table class="reference"> <tbody><tr> <th>Firstname</th> <th>Lastname</th> <th>Points</th> </tr> <tr> <td>Jill</td> <td>Smith</td> <td>50</td> </tr> <tr> <td>Eve</td> <td>Jackson</td> <td>94</td> </tr> <tr> <td>John</td> <td>Doe</td> <td>80</td> </tr> <tr> <td>Adam</td> <td>Johnson</td> <td>67</td> </tr> </tbody></table> 

The spreadsheet only extends by about 60% across the entire PDF file, which just seems random. In addition, the text inside the table is different from the font and the size of the text outside the table.

Any help would be greatly appreciated.

thanks

+6
source share

Source: https://habr.com/ru/post/972597/


All Articles