我正在尝试使用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');
答案 0 :(得分:1)
WriteHTML add-on是一个名为PDF_HTML
的类,它扩展了原始FPDF
。要使用附加组件功能,您必须实例化子类并使用它:
$pdfhtml=new PDF_HTML();
您不需要父类的其他实例($pdf
)。删除它并将$pdf
的所有引用更改为$pdfhtml
,您就可以了:
<?php
define('FPDF_FONTPATH', '../Classes/FPDF/font/');
require ('../Classes/FPDF/fpdf.php');
require ('writeHtml.php');
//create a PDF_HTML object
$pdfhtml=new PDF_HTML();
//set document properties
$pdfhtml->SetAuthor('Author Name');
$pdfhtml->SetTitle('PRESS RELEASE - NAME OF SHOW');
//set font for the entire document
$pdfhtml->SetFont('Helvetica','B',10);
$pdfhtml->SetTextColor(0,0,0);
//set up a page
$pdfhtml->AddPage('P');
// $pdfhtml->SetDisplayMode(real,'default'); //<-- commented this line, what is real?
//display the top block
$contact = 'Contact Name';
$addline1 = '4002 2nd Ave NE, #2';
$addline2 = 'Address Line 2';
$cityzip = 'Seattle, WA 98105';
$pdfhtml->Cell(0, 4, 'PRESS RELEASE', 0, 0, 'L');
$pdfhtml->Cell(0, 4, 'FOR IMMEDIATE RELEASE', 0, 1, 'R');
$pdfhtml->Cell(0, 4, 'CONTACT: '.$contact, 0, 0, 'L');
$pdfhtml->Cell(0, 4, 'KILL DATE: August 1, 2014', 0, 1, 'R');
$pdfhtml->Cell(0, 4, $addline1, 0, 1, 'L');
$pdfhtml->Cell(0, 4, $addline2, 0, 1, 'L');
$pdfhtml->Cell(0, 4, $cityzip, 0, 1, 'L');
//display the title
$pdfhtml->SetFontSize(20);
$pdfhtml->Cell(0,10,'PRESS RELEASE TITLE',0,1,'C',0);
//display the sub-title
$pdfhtml->SetFontSize(16);
$pdfhtml->Cell(0,10,'The Subtitle',0,1,'C',0);
//display the italic summary
$pdfhtml->SetXY(10,55);
$pdfhtml->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.';
$pdfhtml->MultiCell(0, 4, $summary , 0, 'J');
//display the main content
$pdfhtml->SetFont('Helvetica','',10);
$maincontent = '
First line.
Second Line?
<ul>
<li>
Item 1
</li>
</ul>
';
$pdfhtml->WriteHTML($maincontent);
//Output the document
$pdfhtml->Output('example1.pdf','I');
请注意,我更改了顶部的包含路径。我还评论了您呼叫SetDisplayMode
的行。
答案 1 :(得分:0)
你可能有一些元素,例如你的pdf html中的不平衡。某些元素可能尚未关闭或启动。 找到这个问题我花了2天时间。