duanjiaolao1187 2016-10-06 15:55
浏览 36

mPDF不回显数据

I am using mPDF to download the HTML form. There is one button and on clicking on that it download the form.

PHP function to download PDF:

function download($id)
    {
        $data = $this->test_model->getMoreDataByID($id);
        $name = str_replace(' ', "-", strtolower($data['name']));
        $time = time();
        $file_name = $name.$time.$id;
        $html=$this->load->view('folder/form_download', $data, true);
        $pdfFilePath = $file_name.".pdf";
        $this->load->library('m_pdf');
        $this->m_pdf->pdf->SetDisplayMode('fullpage');
        $this->m_pdf->pdf->WriteHTML($html);
        $this->m_pdf->pdf->Output($pdfFilePath, "D");
    }

Here is the PDF data to be generate:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Annex C</title>

    <style>
        body {
            font-family: "futura_md_btmedium";
        }
        .info_head{
            font-size:20px;
            font-weight:bold;
        }
        .invoice-box{
            max-width:800px;
            margin:auto;
            border:2px solid #000;
            font-size:16px;
            color:#555;
        }

        .invoice-box table{
            width:100%;
            line-height:inherit;
        }

        .mtopm54 {
            margin-top: -54px;
        }

        .mtopm47 {
            margin-top: -47px;
        }

        .t-align {
            text-align: center;
        }

        .invoice-box table td{
            padding:5px;
            vertical-align:top;
        }

        .invoice-box table tr.details td {
            padding-bottom: 10px;
            border: 0.5px dotted #ddd;
        }

        .invoice-box table tr.top table td.title{
            font-size:11px;
            color:#333;
            text-align: center;
        }

        .invoice-box table tr.information table td{
            padding-bottom:40px;
        }

        .invoice-box table tr.heading td{
            background:#0776b8;
            font-weight:bold;
            text-align:center;
            color:#fff;
        }

        .invoice-box table tr.details td{
            text-align:center;
        }

        .total_details td{
            border-top:1px solid #ddd;
            font-weight:bold;
        }        

        .invoice-box table tr.item.last td{
            border-bottom:none;
        }

        @media only screen and (max-width: 600px) {
            .invoice-box table tr.top table td{
                width:100%;
                display:block;
                text-align:center;
            }

            .invoice-box table tr.information table td{
                width:100%;
                display:block;
                text-align:center;
            }
        }
        .separator td{
            padding-bottom:40px !important;
        }
        .bold-font {
            font-weight: bold;
        }
        .bottom-border {
            border-bottom: 1px solid #000;
        }
        .pbottopm-border {
            padding-bottom: 4px;
            border-bottom: 1px dotted #000;
        }
        .remark {
            border-bottom: 1px solid #000;
            padding-bottom: 2px;
        }
    </style>
</head>

<body>
    <div class="invoice-box">
        <table cellpadding="0" cellspacing="0">
            <table class="t-align mtopm54 bottom-border">
                <tr class="top">
                    <td colspan="4">
                        <tr>
                            <td class="title">
                                <b class="bold-font">This portion is to be completed where the solicitor is acting for the Corporation. <br>
                                    SEARCHES ON THE RELEVANT PARTY <br> 
                                </b> ("Relevant Party" as defined in the instruction on Legal Requisitions and Searches (Annex C))
                            </td>
                        </tr>
                    </td>
                </tr>            
            </table>

            <table class="mtopm54">
                <tr>
                    <td style="width:16%">
                        <strong>Corporation Name:</strong>                        
                    </td>
                    <td style="width:70%">
                        <span class="pbottopm-border"><?= $corp_name; ?></span>
                    </td>
                </tr>
            </table>

            <table class="mtopm54 bottom-border">
                <tr>
                    <td style="width:16%">
                        <b>Accounting Corporate and Regulatory Authority ("ACRA") search (copy to be enclosed)</b>
                    </td>
                </tr>
            </table>

            <table class="mtopm54">
                <tr>
                    <td>
                        1) Does the ACRA search disclose any charge or debenture against the company?
                    </td>
                </tr>
            </table>
            <table class="mtopm47">
                <tr>
                <td  style="width:16%">
                        <input type="checkbox" <?php echo ($q_one=='No' ? 'checked' : '');?> name="q_one" class="" value="No" id="q_one"><span class="mleft5">No</span>
                        <input type="checkbox" <?php echo ($q_one=='Yes' ? 'checked' : '');?> name="q_one" class="" value="Yes" id="q_one"><span class="mleft5">Yes</span>
                    </td>
                    <td>
                        <span>If yes, please provide details (including relevant copies) of the charge or debenture or any other encumbrances against the company immediately.</span>
                    </td>
                </tr>
            </table>

        </table>
    </div>
</body>
</html>

It is generating PDF like this: PDF-Generated

It is generating the HTML: HTML

But some how it is not generating that data into PDF file. Any reason?

  • 写回答

1条回答 默认 最新

  • doudizhi947129 2016-10-11 10:53
    关注

    I can't be sure, but it may be to do with mistakes in your HTML.

    You currently have a table element inside another table element like this:

    <table cellpadding="0" cellspacing="0">
        <table class="t-align mtopm54 bottom-border">
    

    This is not valid HTML. If you want to put a table inside another table, you need to place it inside a table cell. E.g.

    This is WRONG

    <table>
        <table>
            <tbody>
                <tr>
                    <td>Content</td>
                </tr>
            </tbody>
        </table>
    </table>
    

    This is RIGHT

    <table>
        <tbody>
            <tr>
                <td>
                    <table>
                        <tbody>
                            <tr>
                                <td>Content</td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答