Search code examples
pdfdownloadexportlandscape-portrait

Landscape Orientation When Download Table HTML to PDF Using TableHTMLExport Plugin


I am trying to download PDF table HTML using TableHTMLExport plugin.

I can download all data in table with this code:

<table class="table downloadPDF" id="example">
        <thead>
            <tr>
                <th>Column 1</th>
                <th>Column 2</th>
                <th>Column 3</th>
                <th>Column 4</th>
                <th>Column 5</th>
                <th>Column 6</th>
                <th>Column 7</th>
                <th>Column 8</th>
                <th>Column 9</th>
                <th>Column 10</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Value 1</td>
                <td>Value 2</td>
                <td>Value 3</td>
                <td>Value 4</td>
                <td>Value 5</td>
                <td>Value 6</td>
                <td>Value 7</td>
                <td>Value 8</td>
                <td>Value 9</td>
                <td>Value 10</td>
            </tr>
        </tbody>
    </table>
    <button id="pdf" class="btn btn-danger">TO PDF</button>

<script>
    $('#pdf').on('click', function () {
      $(".downloadPDF").tableHTMLExport({type:'pdf', filename:'tst.pdf' });
    })
</script>

But I can't see all value of column in PDF result because my columns is to many and paper orientation is portrait. How to change paper orientation to landscape when download from HTML to PDF?


Solution

  • I decide to change TableHTMLExport plugin with TableExport plugin. I think TableExport plugin is more powerfull and easy to use because it has many libraries. I also can print PDF with landscape orientation when use this plugin.

    TableExport plugin: documentation TableExport, repository TableExport