导出pdf文档与php使用dompdf [英] Export pdf document with php using dompdf

查看:873
本文介绍了导出pdf文档与php使用dompdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,所以我试图导出pdf文档与php使用dompdf,一切顺利,但当我发送php变量显示它添加到结束和开始。%27

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

在这种情况下,变量$ number_cadastral位于%27之前,因此结果将是:%27.787883434。 %27.为什么要添加这个%27?帮助我

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

推荐答案

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

尝试此代码。

这篇关于导出pdf文档与php使用dompdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆