HTML表渲染为PDF.Pdf格式的内容不是标签格式

HTML Tabel rendering to PDF. Content in Pdf not tabel format

本文关键字:格式 标签 Pdf PDF HTML      更新时间:2023-09-26

在这里我试图使用一个HTML页面表内容的PDF。对我来说,它在创建PDF和下载工作很好,但问题是我没有得到正确的表格格式,我在HTML页面中使用(它在网页上的样子,我也需要在PDF)。下面我给我的代码和表结构。我正在使用HTML表导出jQuery插件

我的HTML代码

<!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>

使用inline-css代替外部CSS据我所知,只有表元素上的内联CSS才能正确导出。我在这里找到了这个

我知道我来晚了一点。但我把这个贴出来,以防有人在这里寻找答案。

我们可以使用jsPDF自动表插件添加一个格式良好的表格到您的pdf。要使用它,请下载并包含jspdf.plugin.autotable.js和jspdf.min.js。

它使用简单,并且有多种表格格式。

您可以在GitHub存储库中找到完整的文档