1

I would like to create a html template that when print in chrome browser, the header and footer will fixed on the top and bottom of the page. The tbody will be in between of header and footer. It's height is the total height after minus header and footer. If the tbody exceed the height, it will break into next page. Now, I am having issue that when printing the html template, the tbody will overlap the tfoot and thead on the next page, as shown in these pictures. Please kindly advice. My html template is on the below github link.

OverlapFooter OverlapFooterAndHeader.

The HTML is in my github repository. Please help to check on this link.

MyTemplate

Below is my code and my reference for dealing page break for large html table.

Reference

This is a short snippet of my code structure

<!DOCTYPE HTML>
<html>

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Test</title>
        <style type="text/css">
            html,
            body,
            * {
                margin: 0;
                padding: 0;
            }

            table {
                page-break-inside: auto;
                border-collapse: collapse;
            }

            tr {
                page-break-inside: avoid;
                page-break-after: auto
            }

            td {
                page-break-inside: avoid;
                page-break-after: auto
            }

            div {
                page-break-inside: avoid;
            }

            thead {
                display: table-header-group;
            }

            tfoot {
                display: table-footer-group
            }

            /* tbody {
                display: table;
                width: 100%;
                table-layout: fixed;
            } */

            @media screen {
                div.divFooter {
                    display: none;
                }

                div.divHeader {
                    display: none;
                }


            }

            @media print {
                div.divFooter {
                    position: fixed;
                    height: 250px;
                    bottom: 0;
                    left: 0;
                    text-align: left;
                    display: block;
                }

                div.divHeader {
                    position: fixed;
                    height: 100px;
                    top: 0;
                    left: 0;
                    display: block;

                }

                div.divBody {
                    height: calc(100% - 350px);
                    position: relative;
                    text-align: left;
                    margin-top: 20rem;
                    margin-bottom: -20rem;
                    page-break-after: always;
                }
            }
        </style>
    </head>

    <body>
        <table style="width: 100%;">
            <thead>
                <tr>
                    <th>
                        <div class="divHeader" style="display: inline-block; width: 100%;">
                            <table style="width: 100%; text-align: left;">
                                <tr>
                                    <td><img style="width: 120px; height: 120px;"
                                            src="https://bp.doctor2u.my/assets/img/bplogo.png">
                                    </td>
                                    <td style="vertical-align: top; ">
                                        <table>
                                            <tr style="margin-left: 1 rem;">
                                                <td colspan="2">
                                                    <a
                                                        style="font-family:Helvetica;font-weight: bold; font-size: 20pt;">
                                                        PATHOLOGY
                                                        REPORT
                                                    </a>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2">
                                                    <span>B. P. CLINICAL LAB SDN. BHD. (152314-H)</span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <span>[BranchAddress] ,</span>
                                                </td>
                                                <td>
                                                    <span>&nbsp;&nbsp;&nbsp;[BranchEmail]</span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <label>Tel : </label><span>[BranchTel]</span>
                                                </td>
                                                <td>
                                                    <label>Fax : </label><span>[BranchFax]</span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2">
                                                    <label>GST Reg No. : </label><span>[GST]</span>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                            <table style="width: 100%; text-align: left;">
                                <tr>
                                    <td>
                                        <label>Client PatientID :</label><span>[ClientId]</span>
                                    </td>
                                    <td colspan="2">
                                        <label>Barcode :</label><span>[LabNo]</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <label>Patient Name :</label><span>[PatientName]</span>
                                    </td>
                                    <td>
                                        <label>Age/Gender :</label><span>[Age] / [Gender]</span>
                                    </td>
                                </tr>
                                <tr class="spaceUnder">
                                    <td>
                                        <label>NRIC No :</label><span>[IC]</span>
                                    </td>
                                    <td>
                                        <label>Refer No :</label><span>[ReferNo]</span>
                                    </td>
                                    <td>
                                        <label>Branch :</label><span>[BranchName]</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <label>Client Name :</label><span>[ClinicName]</span>
                                    </td>
                                    <td>
                                        <label>Tel :</label><span>[Tel]</span>
                                    </td>
                                </tr>
                                <tr class="spaceUnder2">
                                    <td colspan="2">
                                        <label>Doctor’s Name :</label><span>[DoctorName]</span>
                                    </td>
                                    <td>
                                        <label>Fax:</label><span>[Fax]</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3">
                                        <label>Specimen :</label><span>[Specimen]</span><span>-sampled at
                                        </span><span>[SampleDate]</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3">
                                        <label>Received :</label><span>[LabNo] by [ReceivedBranch]
                                            [ReceiveDate]</span>
                                    </td>
                                </tr>
                            </table>
                            <label for="" style="float: right;">Page 2 of 3</label>
                            <table
                                style="border-top: 5px solid black; width: 100%;  border-spacing: 1rem; text-align: center;"
                                class="spaceUnderTable">
                                <tr class="spaceUnder">
                                    <th>
                                        <label for="">TEST NAME</label>
                                    </th>
                                    <th>
                                        <label for="">RESULT</label>
                                    </th>
                                    <th>
                                        <label for="">UNIT</label>
                                    </th>
                                    <th>
                                        <label for="">REFERENCE NOTE</label>
                                    </th>
                                    <th>
                                        <label for="">RESULT</label>
                                    </th>
                                    <th>
                                        <label for="">UNIT</label>
                                    </th>
                                    <th>
                                        <label for="">REFERENCE NOTE</label>
                                    </th>
                                </tr>
                            </table>
                        </div>
                    </th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>
                        <div class="divFooter" style="display: inline-block; width: 100%; left:0px;
                                    bottom:0px; text-align: left;">
                            <table style="width: 100%; margin-top: 1rem;">
                                <tr>
                                    <td rowspan="7" style="width: 20%;">
                                        <!-- [Image] -->
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Results validated and authorised through the Laboratory information
                                        System.
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Results checked and authorised for release
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Test done at B.P. Clinical Lab Sdn. Bhd. (Ipoh) 273-B Jalan Raja
                                        Permaisuri
                                        Bainun,
                                        30250
                                        Ipoh, Perak.
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Tel: 05-2559090 Fax:05-2419226
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Ipoh lab is a MS ISO 15189 accredited lab
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        * Not SAMM Accredited
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="4">
                                        <p style=" margin-top: 1rem; text-align: center;">
                                            For further confirmation, please
                                            repeat test with another
                                            fresh
                                            specimen, if desired.
                                            Should
                                            you
                                            have further enquiries, please
                                            contact your nearest BP branch or mail us at
                                            corpcare@bphealthcare.com
                                            <br>
                                            [BranchAddress], [BranchEmail]
                                            Tel: <span>[Tel]</span>,
                                            Fax: [Fax]
                                        </p>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </th>
                </tr>
            </tfoot>
            <tbody>
                <tr>
                    <td>
                        <div class="divBody">
                            <table style="width: 100%;  border-spacing: 1rem; text-align: center;"
                                class="spaceUnderTable">
                                <!-- LIPIDS STUDIES -->
                                <tr>
                                    <td style="text-align: left;">
                                        <label for=""><strong>Full Blood Count</strong></label>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: left;">
                                        <label for="">Total RBC</label>
                                    </td>
                                    <td>
                                        <label for="">[TotalRBCResult]</label>
                                    </td>
                                    <td>
                                        <label for="">[TotalRBCUnit]</label>
                                    </td>
                                    <td>
                                        <label for="">[TotalRBCRange]</label>
                                    </td>
                                    <td>
                                        <label for="">[TotalRBCResult2]</label>
                                    </td>
                                    <td>
                                        <label for="">[TotalRBCUnit2]</label>
                                    </td>
                                    <td>
                                        <label for="">[TotalRBCRange2]</label>
                                    </td>
                                </tr>
                               <!-- More row -->
                                <br>
                                <br>

                            </table>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </body>

</html>
Shawn Teh
  • 39
  • 10

0 Answers0