Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用FPDF除以零误差+;WriteHTML附加组件_Php_Pdf_Pdf Generation_Fpdf - Fatal编程技术网

Php 用FPDF除以零误差+;WriteHTML附加组件

Php 用FPDF除以零误差+;WriteHTML附加组件,php,pdf,pdf-generation,fpdf,Php,Pdf,Pdf Generation,Fpdf,我正在尝试使用FPDF生成at PDF文件,这是我第一次尝试 我有最新的FPDF文件,还设置了WriteHTML附加组件。下面的代码一直运行到最底部的WriteHTML部分。我在第796行收到错误“警告:在/home4/fwall/public_html/fpdf/fpdf.php中被零除”。当我查看FPDF.php的第796行时,我发现: // Output text in flowing mode $cw = &$this->CurrentFont['cw'];

我正在尝试使用FPDF生成at 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;
//以流动模式输出文本
$cw=&$this->CurrentFont['cw'];
$w=$this->w-$this->rMargin-$this->x;
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;//字体大小!=0) {
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;//多小区(0,4,$summary,0,J');
//显示主要内容
$pdf->SetFont('Helvetica','',10);
$maincontent='1〕
第一行。
第二线?
  • 项目1
'; $pdfhtml->WriteHTML($maincontent); //输出文档 $pdf->Output('example1.pdf','I');
您的pdf html中可能存在某些元素,例如不平衡。某些元素可能尚未关闭或启动。 找到这个问题花了我两天时间。

是一个名为
PDF\u 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');

找出为什么
$this->FontSize
设置为零并修复它?顺便说一句,你的
if
语句提到了
$thisFontSize
,我很确定它是
$this->FontSize
的一个单独变量。谢谢,这是问题中的一个输入错误,在我的代码中是正确的。我会在上面修复它。是的,我一直在努力找出你的答案t为什么设置为0却没有运气。我希望对FPDF有更多经验的人能够启发我。你能提供一个到你正在使用的WriteHTML加载项的链接吗?当然,给你:你可以用它直接向用户发表评论。这样,用户会收到你的评论。太好了!非常感谢。FPDF仍然是我的一个小朋友你的回答给了我一些启示(另外,它还有效!)。我确实注意到呈现的html没有显示任何样式或格式,因此我将研究如何使其更好地工作,但这至少让我克服了功能问题。噢,而且,SetDisplayMode设置为real意味着PDF的默认视图将是文档实际尺寸的100%,只要我看得出来。虽然看起来没有它,但它工作得很好。好的,那么你缺少了字符串real周围的引号。
$pdfhtml=new PDF_HTML();
<?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');