Search code examples
phpcodeignitercodeigniter-2php-5.3dompdf

Export pdf document with php using dompdf


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


Solution

  • <?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.