使用dompdf导出使用php导出pdf文档

时间:2014-08-28 06:40:59

标签: php codeigniter codeigniter-2 php-5.3 dompdf

我有一个问题,所以我尝试使用dompdf导出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.787883434。%27.为什么要添加这个%27 ??请帮帮我

1 个答案:

答案 0 :(得分: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");
    }
?>

试试这段代码。