使用 PHP 生成 PDF

发布于 2024-09-29 21:18:42 字数 1994 浏览 1 评论 0原文

如何使用MYSQL查询超过15个字段并换行生成PDF文档?我已经使用 fpdf 选项生成了 PDF。但我只创建了 8 个带有 nowrap 文本的字段。所以请任何人解决解决方案。谢谢。

例如。我用 nowrap 文本创建的。

$pdf=new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);
$pdf->SetTextColor(4,126,167);
$pdf->Cell(10,10,'Worksheet Report');
$pdf->Ln();

//Column titles
$header=array('Client','Team In Charge','Staff In Charge','Priority','Master Activity','Sub Activity','Last Reports Sent','Job in Hand','Team Incharge Notes','External Due Date','Befree Due Date','Status');
$pdf->SetFont('Arial','B',6);
$pdf->FancyTable($header);

$pdf->SetFont('Arial','',5);
$pdf->SetFillColor(255,255,255);
$pdf->SetTextColor(0);
$pdf->SetLineWidth(.2);
$sql=$_SESSION['query'];
$result = mysql_query($sql);
while($row = @mysql_fetch_array($result)){
$pdf->Cell(15,10,htmlspecialchars($row["lp_wrk_CompanyName"]),1,0,'T',true);
$pdf->Cell(17,10,$commonUses->getFirstLastName($row["wrk_TeamInCharge"]),1,0,'T',true);
$pdf->Cell(17,10,$commonUses->getFirstLastName($row["wrk_StaffInCharge"]),1,0,'T',true);
$pdf->Cell(12,10,htmlspecialchars($row["lp_wrk_priority"]),1,0,'T',true);
$pdf->Cell(17,10,htmlspecialchars($row["lp_wrk_MasCode"]).($row["lp_wrk_MasCode"]!=""? "-":"").htmlspecialchars($row["lp_wrk_MasterActivity"]),1,0,'T',true);
$pdf->Cell(15,10,htmlspecialchars($row["lp_wrk_SubCode"]).($row["lp_wrk_SubCode"]!=""? "-":"").htmlspecialchars($row["lp_wrk_SubActivity"]),1,0,'T',true);
$pdf->Cell(19,10,htmlspecialchars($row["wrk_Details"]),1,0,'T',true);
$pdf->Cell(18,10,htmlspecialchars($row["wrk_Notes"]),1,0,'T',true);
$pdf->Cell(19,10,htmlspecialchars($row["wrk_TeamInChargeNotes"]),1,0,'T',true);
$pdf->Cell(18,10,$commonUses->showGridDateFormat($row["wrk_DueDate"]),1,0,'T',true);
$pdf->Cell(18,10,$commonUses->showGridDateFormat($row["wrk_InternalDueDate"]),1,0,'T',true);

$pdf->Cell(15,10,htmlspecialchars($row["lp_wrk_Status"]),1,0,'T',true);
$pdf->Ln();
}

how generate PDF document with MYSQL query more than 15 fields with wrap text? I have generated PDF with fpdf option. but I have created only 8 fields with nowrap text. so any one please solve the solutions. thanks.

For example. I have created with nowrap text.

$pdf=new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);
$pdf->SetTextColor(4,126,167);
$pdf->Cell(10,10,'Worksheet Report');
$pdf->Ln();

//Column titles
$header=array('Client','Team In Charge','Staff In Charge','Priority','Master Activity','Sub Activity','Last Reports Sent','Job in Hand','Team Incharge Notes','External Due Date','Befree Due Date','Status');
$pdf->SetFont('Arial','B',6);
$pdf->FancyTable($header);

$pdf->SetFont('Arial','',5);
$pdf->SetFillColor(255,255,255);
$pdf->SetTextColor(0);
$pdf->SetLineWidth(.2);
$sql=$_SESSION['query'];
$result = mysql_query($sql);
while($row = @mysql_fetch_array($result)){
$pdf->Cell(15,10,htmlspecialchars($row["lp_wrk_CompanyName"]),1,0,'T',true);
$pdf->Cell(17,10,$commonUses->getFirstLastName($row["wrk_TeamInCharge"]),1,0,'T',true);
$pdf->Cell(17,10,$commonUses->getFirstLastName($row["wrk_StaffInCharge"]),1,0,'T',true);
$pdf->Cell(12,10,htmlspecialchars($row["lp_wrk_priority"]),1,0,'T',true);
$pdf->Cell(17,10,htmlspecialchars($row["lp_wrk_MasCode"]).($row["lp_wrk_MasCode"]!=""? "-":"").htmlspecialchars($row["lp_wrk_MasterActivity"]),1,0,'T',true);
$pdf->Cell(15,10,htmlspecialchars($row["lp_wrk_SubCode"]).($row["lp_wrk_SubCode"]!=""? "-":"").htmlspecialchars($row["lp_wrk_SubActivity"]),1,0,'T',true);
$pdf->Cell(19,10,htmlspecialchars($row["wrk_Details"]),1,0,'T',true);
$pdf->Cell(18,10,htmlspecialchars($row["wrk_Notes"]),1,0,'T',true);
$pdf->Cell(19,10,htmlspecialchars($row["wrk_TeamInChargeNotes"]),1,0,'T',true);
$pdf->Cell(18,10,$commonUses->showGridDateFormat($row["wrk_DueDate"]),1,0,'T',true);
$pdf->Cell(18,10,$commonUses->showGridDateFormat($row["wrk_InternalDueDate"]),1,0,'T',true);

$pdf->Cell(15,10,htmlspecialchars($row["lp_wrk_Status"]),1,0,'T',true);
$pdf->Ln();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一口甜 2024-10-06 21:18:42

有一个名为 DocRaptor 的网络服务,它使用 Prince 从 html 生成 pdf 和 xls。他们提供免费计划以及更大的付费计划。

There's a webservice called DocRaptor that uses Prince to generate pdf and xls from html. They offer a free plan as well as larger paid plans.

梦回旧景 2024-10-06 21:18:42

检查此网页链接:-
http://qualitypoint.blogspot.com /2010/07/resolved-wrap-text-issue-in-fpdf-table.html
http://blog.themeforest.net/tutorials/how-to-create-pdf-files-with-php/

我希望它对您有用:)

check this web link :-
http://qualitypoint.blogspot.com/2010/07/resolved-wrap-text-issue-in-fpdf-table.html
http://blog.themeforest.net/tutorials/how-to-create-pdf-files-with-php/

I hope it is useful for you :)

吃→可爱长大的 2024-10-06 21:18:42

查看 dompdf 类。它从您的 html 代码生成 pdf,因此更容易、更快捷地获得您想要的结果。它对浮动仍然有点挑剔,所以你必须想象你是在 90 年代并做一个基于表格的设计。

Have a look at the dompdf class. It generates the pdf from your html code so it's much easier and quicker to get the results you want. It's still a bit finicky with floats so you have to imagine your are in the 90's and do a table based design.

书信已泛黄 2024-10-06 21:18:42

我的建议是打印出 html 表格,而不是转换成 pdf:更容易、更快、更灵活:当你有 html 文档时,如果你需要的话,会很容易(例如)转换成 jpg到未来。

如果您可以在服务器上安装软件,我推荐您wkhtmltopdf

您生成 html 文件,然后 wkhtmltopdf 将其转换为 pdf,并具有完整(基于 webkit)的 css 支持。

另外,我发现 html2ps 做得很好,但处理大文件时速度相当慢。 .css 支持很好,但不能保证它会支持 css3。

My advice is to print out the table in html, than convert in into pdf: is easier, faster, and more flexible: when you have the html documents, will be easy (for example) convert into a jpg, if you'll need to in the future.

If you can install software on your server, i raccomend you wkhtmltopdf.

You generate the html file, and wkhtmltopdf convert it to pdf, with full (webkit based) css support.

Else, i've found that html2ps doeas a great job, but is quite slower with large files.. css support is good, but no guarantee that it will support css3, for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文