使用dompdf导出带有php的pdf文档



我有一个问题要问你,所以我尝试使用dompdf导出带有php的pdf文档,一切都很顺利,但当我发送php变量来显示时,它会添加到末尾和开头。%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");

在这种情况下,变量$number_cadastral在前面。%27,那么结果将是:%27.7787883434.%27为什么要加这个%27??请帮帮我

<?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");
    }
?>

试试这个代码。

最新更新