我使用CodeIgniter和mpdf库来创建pdf文件。
直到我尝试添加页脚才能正常工作。 每次添加页脚时,每当我尝试打开生成的文件时,都会收到此错误:
文件不以'%PDF开头 - '本地\ EWH-6160-0
如果我跳过页脚,它运行正常,我不明白错误是如何与页脚相关的。
这是创建pdf的控制器:
public function print_beneficiaries($cod){
$mpdf = new mPDF( 'utf-8', 'A3' );
$name = $this->natural_md->client_name($cod);
$account = $this->formats->retrieve_account($cod);
$data = $this->formats->beneficiaries( $cod );
$date = $this->formats->mult_contract( $cod );
$list = array();
if($data > 0){
$i = 1;
foreach ( $data as $benef ){
array_push( $list, array(
'cod' => $cod,
'id_beneficiary' => $benef['id_beneficiary'],
'name' => $benef['beneficiary_name'],
'relationship' => $benef['relationship'],
'benef_percentage' => $benef['benef_percentage'],
'identification' => $benef['identification'],
'identification_type' => $benef['identification_type'],
'address' => $benef['address'],
'email' => $benef['email'],
'telephone' => $benef['telephone'],
'celphone' => $benef['celphone'],
'letter' => $this->utilities->get_letter($i)
) );
$i = $i + 1;
}
}
else
$list = array();
$mpdf->SetFooter("{PAGENO}/{nb}");
$mpdf->WriteHTML($this->load->view( 'pdf/pn_beneficiaries', array(
'list' => $list,
'account_name' => ucwords($name[0]['names']),
'account_id' => $account == null ? 0 : $account->id,
'account' => $account == '' ? 0 :$cuenta->account_name,
'day' => sprintf('%02d', $date[0]['day']),
'month' => sprintf('%02d', $date[0]['month']),
'year' => $date[0]['year'],
), true ) );
$mpdf->Output("Beneficiaries - ".$cod.".pdf", "I");
}
控制器从中检索数据的视图是:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Beneficiaries</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="<?php echo base_url();?
>/assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="<?php echo base_url();?
>/assets/css/font.css" />
<style>
body{
color: #0a0a0a;
font-size: 12px;
font-family: Calibri, sans-serif;
}
.foot{
position: absolute;
bottom: 0;
left: 900px;
width: 100%;
float: right;
}
.espacio{
margin-top: 4px;
width: 900px;
}
.espacio h3{
text-align: center;
font-weight: 700;
}
.per{
font-size: 14px;
text-align: justify;
}
table{
font-size: 16px;
}
th{
padding:4px;
text-align: center;
}
table.border td{
border: solid 2px #B1B1B1;
}
td{
padding:4px;
}
u{
height: 2px;
}
.logo{
text-align: center;
}
@media print {
#with_print {
display: none;
}
}
</style>
</head>
<body>
<header>
<div class="row">
<div class="container logo">
<img src="<?php echo base_url();?>/assets/img/logo-inver-
new.jpg" width="180px">
</div>
</div>
</header>
<div class="container espacio" >
<h3>
Beneficiary designation
</h3>
<div class="espacio per">
<p>
some text
</p>
</div>
<div class="row">
<div class="container">
<table border="1" class="border">
<tr>
<td colspan="3" style=" background-color: #30859B; color: #fff;
font-size: 16px; margin: 5px;">Fecha</td>
</tr>
<tr>
<td style=" font-size: 16px;"><?php echo $day; ?></td>
<td style=" font-size: 16px;"><?php echo $month; ?></td>
<td style=" font-size: 16px;"><?php echo $year; ?></td>
</tr>
</table>
</div>
</div>
<br>
<div class="row">
<?php $cont = 0; $filas=count($list);?>
<?php foreach ($list as $row):?>
<div class="container">
<table border="1" align="center" class="border">
<tr>
<td colspan="2" style=" background-color: #30859B; color:
#fff;">Beneficiario <?php echo $row['letter']; ?></td>
</tr>
<tr>
<td colspan="2">Nombre del Beneficiario: <span style="font-
size: 18px; font-style: italic; color:
#2b2b2b;">  <?php echo $row['name']; ?> </span>
</td>
</tr>
<tr>
<td style="width: 500px;">Parentesco: <span style="font-
size: 18px; font-style: italic; color:
#2b2b2b;">  <?php echo $row['relationship']; ?>
</span> </td>
<td style="width: 500px;">% del Beneficiario: <span
style="font-size: 18px; font-style: italic; color:
#2b2b2b;">  
<?php
if(!empty($row['benef_percentage']))
{echo $row['benef_percentage'].' %';}
?></span> </td>
</tr>
<tr>
<td>No. Identificación: <span style="font-size: 18px; font-
style: italic; color: #2b2b2b;">  <?php echo
$row['identification']; ?></span> </td>
<td>Tipo de Identificación: <span style="font-size: 18px;
font-style: italic; color: #2b2b2b;">  <?php echo
$row['identification_type']; ?> </span> </td>
</tr>
<tr>
<td colspan="2">Dirección del Beneficiario: <span
style="font-size: 18px; font-style: italic; color:
#2b2b2b;">   <?php echo $row['address']; ?>
</span> </td>
</tr>
<tr>
<td colspan="2">Correo Electrónico: <span style="font-size:
18px; font-style: italic; color: #2b2b2b;">   <?
php echo $row['email']; ?></span> </td>
</tr>
<tr>
<td>Teléfono Domicilio: <span style="font-size: 18px; font-
style: italic; color: #2b2b2b;">  <?php echo
$row['telephone']; ?></span> </td>
<td>Teléfono Celular: <span style="font-size: 18px; font-
style: italic; color: #2b2b2b;">  <?php echo
$row['celphone']; ?> </span> </td>
</tr>
</table>
</div>
<?php $cont++;
if ($cont%5==0 && $filas>5) {
echo '
<pagebreak>
';
}
?>
<?php endforeach; ?>
</div>
<br>
<div class="col-xs-12">
<table style="margin-top: 10px;">
<tr>
<td>Nombre de la cuenta: <?php echo $filas ?></td>
<td style="border-bottom: solid 1px #000; width: 100%"><?php
if (isset($account) && ($account!='')) {
echo $account;
}else{
echo $account_name;
}
?></td>
</tr>
</table>
</div>
<div class="col-xs-12 espacio">
<p style="text-align: justify;"><span style=" font-weight:
bold;">Nota:</span>Other text</p>
</div>
<div class="col-xs-12">
<table style="margin-top: 10px;">
<tr >
<td style="width: 100px;"></td>
<td style="border-top: solid 1px #000; width: 250px; text-
align: center; font-size: 16px;" >Firma del Cliente</td>
<td style="width: 100px;"></td>
<td style="border-top: solid 1px #000; ; width: 350px; text-
align: center; font-size: 16px;" >Firma del
Cliente<br>Cuenta Mancomunada</td>
<td style="width: 100px;"></td>
<td style="border-top: solid 1px #000;width: 290px; text-
align: center; font-size: 16px;">
Firma del Funcionario IPB
</td>
</tr>
</table>
</div>
</div>
</div>
</body>
答案 0 :(得分:0)
我在类似的帖子中找到了答案。我在word上打开文件,错误是: preg_replace():不推荐使用/ e修饰符,在mpdf.php文件行12492上使用preg_replace_callback 。我搜索了解决方案,只需更改原始代码:$hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd);
到此:$hd = preg_replace_callback('/\{DATE\s+(.*?)\}/m', function($m){ return date($m[1]);},$hd);