使用dompdf使用php导出pdf文档
我有一个问题要问你,所以我尝试使用dompdf用php导出pdf文档,一切都很顺利,但当我发送php变量以显示它的添加到末尾和开头时。%27使用dompdf使用php导出pdf文档,php,codeigniter,codeigniter-2,php-5.3,dompdf,Php,Codeigniter,Codeigniter 2,Php 5.3,Dompdf,我有一个问题要问你,所以我尝试使用dompdf用php导出pdf文档,一切都很顺利,但当我发送php变量以显示它的添加到末尾和开头时。%27 public function generateTitlePage($number_cadastral='') { $this->load->library('dompdf_gen'); $dompdf = new DOMPDF(); $html = <<<HTML <html&g
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");
公共函数generateTlePage($number\u地籍=“”)
{
$this->load->library('dompdf_gen');
$dompdf=新的dompdf();
$html=stream(“welcome.pdf”);
在本例中,变量$number\U cadastral在前面。%27,因此结果将是:%27.7883434。%27。为什么要添加此%27?请帮助我,最好将所有html都放在视图中,并使用$html=$this->load->view('html\u view\u name',$data,TRUE);并使用该html创建pdfdid您是否检查您的号码不包含任何空格?我不太喜欢所选的答案,它绕过了问题而没有实际解决它。您是否检查了变量是否不包含额外字符。%27似乎是单引号URL编码的。请尝试回显
$html
变量而不是通过dompdf运行它并查看结果。@erhaneluion您检查过27之前是否有空格吗?是的,没有空格pdf现在无法打开,我认为是preg_replace函数,但最好删除的正则表达式是什么。%27@erhaneluion很高兴它起到了作用。我认为上面提到的是一个很好的例子:)
<?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");
}
?>