【发布时间】:2014-08-31 08:44:21
【问题描述】:
我正在尝试使用 FPDF 生成 PDF 文件,这是我第一次尝试。
我有最新的 FPDF 文件并且还设置了 WriteHTML 插件。下面的代码一直在运行,直到最底部的 WriteHTML 部分。我收到错误“警告:第 796 行 /home4/fwall/public_html/fpdf/fpdf.php 中除以零”。当我查看 FPDF.php 的第 796 行时,我发现:
// Output text in flowing mode
$cw = &$this->CurrentFont['cw'];
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; // <--LINE 796
$s = str_replace("\r",'',$txt);
$nb = strlen($s);
$sep = -1;
$i = 0;
$j = 0;
$l = 0;
$nl = 1;
如果我添加一个条件语句,大致如下:
if ($this->FontSize != 0) {
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; // <--LINE 796
}
我可以让错误消失,但我知道这不可能是正确的。有人在我的代码中看到会导致这种情况的错误吗?
require ('/home4/fwall/public_html/fpdf/fpdf.php');
//create a FPDF object
$pdf=new FPDF();
$pdfhtml=new PDF_HTML();
//set document properties
$pdf->SetAuthor('Author Name');
$pdf->SetTitle('PRESS RELEASE - NAME OF SHOW');
//set font for the entire document
$pdf->SetFont('Helvetica','B',10);
$pdf->SetTextColor(0,0,0);
//set up a page
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default');
//display the top block
$contact = 'Contact Name';
$addline1 = '4002 2nd Ave NE, #2';
$addline2 = 'Address Line 2';
$cityzip = 'Seattle, WA 98105';
$pdf->Cell(0, 4, 'PRESS RELEASE', 0, 0, 'L');
$pdf->Cell(0, 4, 'FOR IMMEDIATE RELEASE', 0, 1, 'R');
$pdf->Cell(0, 4, 'CONTACT: '.$contact, 0, 0, 'L');
$pdf->Cell(0, 4, 'KILL DATE: August 1, 2014', 0, 1, 'R');
$pdf->Cell(0, 4, $addline1, 0, 1, 'L');
$pdf->Cell(0, 4, $addline2, 0, 1, 'L');
$pdf->Cell(0, 4, $cityzip, 0, 1, 'L');
//display the title
$pdf->SetFontSize(20);
$pdf->Cell(0,10,'PRESS RELEASE TITLE',0,1,'C',0);
//display the sub-title
$pdf->SetFontSize(16);
$pdf->Cell(0,10,'The Subtitle',0,1,'C',0);
//display the italic summary
$pdf->SetXY(10,55);
$pdf->SetFont('Helvetica','I',10);
$summary = 'SEATTLE - Theatre Off Jackson presents SPF 8, the annual exhibition of solo performance. Featuring four featured performers and one shorts night, the festival will occur between February 6th and March 1st, 2014. This year\'s festival is an exciting mix of experienced artists and new-comers with exciting stories to tell. From tales of a ten-day vows of silence to what it\'s like growing up with deaf parents and siblings, this year\'s festival is a potpourri of styles and stories.';
$pdf->MultiCell(0, 4, $summary , 0, 'J');
//display the main content
$pdf->SetFont('Helvetica','',10);
$maincontent = '
First line.
Second Line?
<ul>
<li>
Item 1
</li>
</ul>
';
$pdfhtml->WriteHTML($maincontent);
//Output the document
$pdf->Output('example1.pdf','I');
【问题讨论】:
-
找出为什么
$this->FontSize设置为零并修复它?顺便说一句,您的if声明提到了$thisFontSize,我很确定这是$this->FontSize的一个单独变量。 -
谢谢,这是问题中的错字,在我的代码中是正确的。我会在上面修复它。是的,我一直在试图弄清楚为什么它没有运气就设置为 0。我希望对 FPDF 有更多经验的人能够启发我。
-
您能否提供一个指向您正在使用的 WriteHTML 插件的链接?
-
您可以使用comment replies 将评论指向用户。这样,用户就会收到有关您的评论的通知。
标签: php pdf pdf-generation fpdf