1

我需要使用 dom pdf 和 php 生成 pdf。我试过这个,但我得到错误 500,我没有语法错误。如果我尝试:$html='Title here'它有效。我尝试使用外部 php 脚本并使用file_get_contents()函数,但它没有用。任何人都可以帮助我找到使用 php 脚本生成 pdf 的解决方案吗?

这是我的脚本(dompdf/index.php):

<?php

include("dompdf_config.inc.php");
include "../config.php";
include("../db/mysql.php");

$pers=$db->sql_fetchrow($db->sql_query('//-----query here--------'));
$inv=$db->sql_fetchrow($db->sql_query('//-----query here--------'));
$cli=$db->sql_fetchrow($db->sql_query('//-----query here--------'));
$proj=$db->sql_fetchrow($db->sql_query('//-----query here--------'));


$total=$db->sql_query('//-----query here--------');

$ret.=
  '
<html>
<head>

</head>

<body>

<div id="left" style="float:left; margin:0 auto;width400px;">
<strong><h2></h2></strong>

</div>

<div id="left" style="float:left; margin:0 auto;  width:300px; ">
<h2 style="">INVOICE</h2>
<table style="border-style : solid;
border-width:2 px;
border-color : black; width:300px; ">
<tr style="border-bottom: 2px solid black !important;"><th style="border-bottom: 2px solid black !important;">Invoice Date</th><th style="border-bottom: 2px solid black !important;">Invoice No.</th></tr>
<tr><td align="center">'.$inv["date_due"].'</td><td align="center">'.$inv["invoice_no"].'</td></tr>
</table>

</div>
<br />
<div  style="float:left; margin:0 auto;width:100%;margin-top:50px; width=300px;">

<table style="border-style : solid; border-width:2 px; border-color : black; width=400px;">
<tr border="1"><th style="border-bottom: 2px solid black !important;" width="400">INVOICE TO:'.$pers['name'].'</th></tr>
<tr><td width="400">
    '.$cli["name"].'<br />
   '.$cli["street"].'<br />
    '.$cli["city"].'<br /><br />
'.$cli["country"].'<br />
</td></tr>
</table>
</div>
<br />
<div style="float:left; width:600; margin-top:50px;margin-bottom:50px;">

<table style="border-style : solid; border-width:2 px; border-color : black; width=600px;">
<tr width=800px; border="2" style="bordder-bottom: #000 solid;"><th colspan="2" style="border-bottom: 2px solid black !important;width:600px;">INVOICE DESCRIPTION</th></tr>

<tr ><td align="right" width="300"><strong>Project name:</strong></td>
<td>'.$proj["name"].'</td></tr>

<tr><td align="right" width="300"><strong>Job number:</strong></td>
<td width="300">'.$proj["job_no"].'</td></tr>

<tr><td align="right" width="300"><strong>Job reference:</strong></td>
<td width="300"> '.$proj["job_reference"].'</td></tr>

<tr><td align="right" width="300"><strong>Source Language:</strong></td>
<td width="300">'.$proj["source_lang"].'</td></tr>

<tr><td align="right" width="300"><strong>Target Language:</strong></td>
<td width="300">'.$proj["targ_lang"].'</td></tr>

<tr><td align="right" width="300"><strong>Deadline:</strong></td>
<td width="300">'.$proj["deadline"].'</td></tr>


</table>
</div>
<br />
<br />
<div style="margin-top:50px;width:600px;">

<table style="border-style : solid; border-width:2 px; border-color : black; width:600px;">
<tr border="1" style="border-bottom: black solid"><th style="border-bottom: 2px solid black !important;">Task description</th><th  style="border-bottom: 2px solid black !important;">Unit</th><th style="border-bottom: 2px solid black !important;">Qty</th><th  style="border-bottom: 2px solid black !important;">Fee Unit</th><th style="border-bottom: 2px solid black !important;">Amount</th></tr>';
  $ret1="";
 $sum=0;
while($r=$db->sql_fetchrow($total)){

    $task_type=$db->sql_fetchrow($db->sql_query('//-----query here--------'));
$quote_type=$db->sql_fetchrow($db->sql_query('//-----query here--------')); 
$unit=$db->sql_fetchrow($db->sql_query('//-----query here--------'));
 $t_lang=$db->sql_fetchrow($db->sql_query('//-----query here--------')); 
 $s_lang=$db->sql_fetchrow($db->sql_query('//-----query here--------'));
 $price=$db->sql_fetchrow($db->sql_query('//-----query here--------'));
 $amount=$price["unit_fee"]*$r["unit_qty"];
 $sum+=$amount;
$ret.='   
<tr style="alignment-adjust: central;"><td>'.$task_type["task"].'&nbsp;&nbsp;&nbsp; '.$quote_type["client_quote"].'</td><td>'.$unit["name"].'</td><td>'.$r["unit_qty"].'</td><td>'.$price["unit_fee"].'</td><td align="right">'.$amount.' '.$r["currency"].'</td></tr>
 ';
 $curr=$r["currency"];


$ret.= '<tr ><td colspan="4" align="right">Subtotal</td><td colspan="4" align="right">'.$sum.' '.$curr.'</td></tr>
<tr ><td colspan="4" align="right">100% due on'.$r["date_due"].'</td><td colspan="4" align="right">'.$sum.' '.$curr.'</td></tr>
<tr ><td colspan="4" align="right">VAT 0%</td><td colspan="4" align="right">0,0 '.$curr.'</td></tr>
<tr ><td colspan="4" align="right"><strong>TOTAL</strong></td><td colspan="4" align="right"><strong>'.$sum.' '.$curr.'</strong></td></tr>
</tr>
</table>
</div>
<br />
  </table><br />
  </div>

  </body>
  </html>';




  $dompdf = new DOMPDF();
  $dompdf->load_html($ret);
  $dompdf->render();
  $dompdf->stream("Invoice.pdf");
  ?>
4

2 回答 2

1

您的content()函数与文本相呼应。它将它推送到屏幕上,而您想在 $html 中捕获它。改用 return 。

更新

为了将所有查询结果捕获到一个返回值,您可以将它们附加到一个变量,如下所示:

function content() {
// Define the output variable
$output = "";

//Run query
$pers=$db->sql_fetchrow($db->sql_query('select * from clients_persons where person_id='.$_GET["ps"].''));

//Combine query results and html
$output .= $pers['name'];
$output .= " <i>";
$output .= $pers['email'];
$output .= " </i>";

return $output;
}
于 2012-11-13T13:38:28.857 回答
0

检查内存限制是否存在此类问题。

于 2012-11-13T13:50:49.750 回答