Export pdf document with php using dompdf

試著忘記壹切 提交于 2019-12-13 05:17:21

问题


I have a question for you, so I tried to export pdf document with php using dompdf,all goes well but when I send php variables to display it's add to the end and the beginning .%27

public function generateTitlePage($number_cadastral='')
{
    $this->load->library('dompdf_gen');
    $dompdf = new DOMPDF();
    $html = <<<HTML
        <html>
        <head>
            <meta charset="UTF-8">
            <link rel="stylesheet"  type="text/css" media="screen" href="TitlePage.css"  />
        </head>
        <body>
            <div style="margin-top: 100px; text-align: right; padding-right:100px;">
                Number:$number_cadastral
                <div style="width: 150px;margin-left: 535px;size:1;"><hr style="margin:0px;"></div>
            </div>
            <div>
      </body>
        </html>
   HTML;

    $dompdf->load_html($html);
    $dompdf->render();
    $dompdf->stream("welcome.pdf");

In this case variable $number_cadastral is preceded .%27, so the result will be: %27.787883434.%27.Why add this %27??Help me please


回答1:


<?php
    $number_cadastral = ($number_cadastral != "")?preg_replace('/[%]+/','', $number_cadastral):"";
    public function generateTitlePage($number_cadastral){
        $this->load->library('dompdf_gen');
        $dompdf = new DOMPDF();
        $html = '
            <html>
            <head>
                <meta charset="UTF-8">
                <link rel="stylesheet"  type="text/css" media="screen" href="TitlePage.css"  />
            </head>
            <body>
                <div style="margin-top: 100px; text-align: right; padding-right:100px;">
                    Number:'.$number_cadastral.'
                    <div style="width: 150px;margin-left: 535px;size:1;"><hr style="margin:0px;"></div>
                </div>
                <div>
          </body>
            </html>
       ';

        $dompdf->load_html($html);
        $dompdf->render();
        $dompdf->stream("welcome.pdf");
    }
?>

Try this code.



来源:https://stackoverflow.com/questions/25542308/export-pdf-document-with-php-using-dompdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!