HTML Tabel rendering to PDF. Content in Pdf not ta

2019-02-11 10:12发布

问题:

Here i am trying to make a PDF using one HTML page table content. for me its working fine in creating PDF and downloading, but the issue is am not getting correct table format which i used in HTML page (how it looks in web page like that i need in PDF too ). below am giving my code and table structure. i am using HTML table export jQuery plugin

MY HTML CODE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="bootstrap.min.css">
    <!-- jQuery 2.0.2 -->
    <script type="application/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
    <script type="application/javascript" src="tableExport.js"></script>
    <script type="application/javascript" src="jquery.base64.js"></script>
    <script type="application/javascript" src="jspdf/libs/sprintf.js"></script>
    <script type="application/javascript" src="jspdf/jspdf.js"></script>
    <script type="application/javascript" src="jspdf/libs/base64.js"></script>
</head>

<body>
    <div id="example">
        <table class="table table-bordered col-lg-6">
            <tr>
                <th class="text-center" colspan="5">Details</th>
            </tr>
            <tr>
                <th class="text-center">Time</th>
                <th class="text-center">Track</th>
                <th class="text-center">user</th>
                <th class="text-center">linked user's</th>
                <th class="text-center">User section</th>
            </tr>
            <tr>
                <td class="text-center">08:30 - 09:30</td>
                <td class="text-center" colspan="4">nill</td>
            </tr>
            <tr>
                <td class="text-center">09:30 - 12:00</td>
                <td class="text-center Inaugural" colspan="4">Inoo
                    <br> smartphones a big hit in world</td>
            </tr>
            <tr>
                <td class="text-center">09:30 - 12:00</td>
                <td class="text-center Industry" colspan="4">user Key
                    <br>smartphones a big hit in world</td>
            </tr>
            <tr>
                <td class="text-center">12:00 - 13:30</td>
                <td class="text-center Industry" colspan="4">User</td>
            </tr>
            <tr>
                <td class="text-center" rowspan="3">13:30 - 14:30</td>
                <td class="text-center">T Track</td>
                <td class="text-center">T User</td>
                <td class="text-center">smartphones a big hit in world</td>
                <td class="text-center">smartphones a big hit in world smartphones a big hit in world</td>
            </tr>
            <tr>
                <td class="text-center">T track</td>
                <td class="text-center">T user</td>
                <td class="text-center">smartphones a big hit in world</td>
                <td class="text-center">smartphones a big hit in worldsmartphones a big hit in world</td>
            </tr>
            <tr>
                <td class="text-center">T track</td>
                <td class="text-center">T user</td>
                <td class="text-center">smartphones a big hit in world</td>
                <td class="text-center">smartphones a big hit in worldsmartphones a big hit in worldsmartphones a big hit in world</td>
            </tr>
        </table>
    </div>
    <a href="#" onclick="$('#example').tableExport({type:'pdf',escape:'false'});">Genrate</a>
</body>

</html>

回答1:

use inline-css instead of external css To the best of my knowledge, only inline CSS on the table elements will export properly. I were found this here



回答2:

I know I'm a bit late to the game. But I'm posting this in case any one end up here looking for an answer.

We can use jsPDF auto-Table plugin for adding a well formatted table to your pdf. For using it, download and include jspdf.plugin.autotable.js and jspdf.min.js.

It is simple to use and has a good variety of table formats.

You can find the complete documentation in this GitHub repository.