我认为 Mpdf 将是一个不错的选择。它更容易生成发票。我在我的一个项目中使用它。它很容易安装在您的 phalcon 项目中。
步骤 1:通过 cd.. 命令进入项目文件夹。
我希望你已经在你的项目中安装了 composer。
第 2 步:运行此命令“composer require mpdf/mpdf”并等待安装完成。
第3步:去vendor fodder。你会看到“mpdf”已经被添加了。忽略其他文件夹。
第 4 步:转到您的控制器。复制以下行。因为您需要在运行时在自动加载器中加载外部模块。我希望您的供应商文件夹在根目录中。
第 5 步:复制 require_once DIR 。 '../../../vendor/autoload.php';
一切就绪。
第 6 步:转到您的函数,例如 public function pdfgenerateAction(){}
第七步:
public function pdfgenerateAction()
{
$email = $this->request->getPost("email");
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML("<hr>");
//Dont bother about this query.You can use Model as well.Just pass the array value to you foreach loop.
$sheet = $this->modelsManager->createBuilder()
->columns("comment.comment, comment.username, comment.email, comment.postedat,item.name,item.photo,item.view,item.categoryid,item.id")
->From('comment')
->innerjoin('item', 'comment.productid = item.id')
->where("comment.email = '$email' ")
->getQuery()
->execute();
$table = "<table>
<tr>
<td >Given Name</td>
<td >Email</td>
<td >Bird Name</td>
<td >Posted Time</td>
<td >Your comment</td>
<td >Total view by all </td>
</tr>";
foreach ($sheet as $row) {
$table.= "<tr>
<td >$row->username</td>
<td >$row->email</td>
<td >$row->name</td>
<td >$row->postedat</td>
<td >$row->comment</td>
<td >$row->view</td>
</tr>";
}
$table.= '</table>';
$mpdf->WriteHTML($table);
$mpdf->WriteHTML("<hr>");
$mpdf->WriteHTML("<div style='display:block;position:fixed;bottom:0px;height:30px;width:100%' align='center'><strong>Your Footer of PDF</strong></div>");
//$filename = $info->id;
$filename = "Put your file name";
//Crete folder inside your public folder
$mpdf->Output("Foldername/$filename.pdf", 'F');
$this->view->pick('pdf/response');
// $this->flashSession->success("success :: PDF generated");
// $this->response->redirect('user-home');
}