【问题标题】:Generate PDF with PHP使用 PHP 生成 PDF
【发布时间】:2010-11-02 09:04:44
【问题描述】:

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

例如。我用 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();
}

【问题讨论】:

  • 你是怎么做到的 8 个字段和 nowrap text?

标签: php mysql pdf fpdf


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    查看此网页链接:- 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/

    希望对你有用:)

    【讨论】:

      【解决方案3】:

      看看dompdf 类。它从您的 html 代码生成 pdf,因此可以更轻松快捷地获得所需的结果。花车还是有点挑剔,所以你必须想象你是 90 年代的人,做一个基于桌子的设计。

      【讨论】:

        【解决方案4】:

        我的建议是用 html 打印表格,而不是转换成 pdf:更容易、更快、更灵活:当您拥有 html 文档时,如果您有 html 文档,将很容易(例如)转换为 jpg将来需要。

        如果你能在你的服务器上安装软件,我推荐你wkhtmltopdf。

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

        否则,我发现html2ps 做得很好,但处理大文件时速度很慢。css 支持很好,但不能保证它会支持 css3,例如。

        【讨论】:

          猜你喜欢
          • 2010-09-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-06-27
          • 2019-02-11
          • 1970-01-01
          相关资源
          最近更新 更多