2014-07-10 2 views
0

FPDF를 사용하여 PDF 파일로 생성하려고합니다. 처음 시도합니다.FPDF + WriteHTML 추가 기능으로 0으로 나누기

필자는 최신 FPDF 파일을 가지고 있으며 WriteHTML 애드온을 설정했습니다. 아래 코드는 맨 아래에있는 WriteHTML 부분까지 작동합니다. "경고 : 796 행의 /home4/fwall/public_html/fpdf/fpdf.php에서 0으로 나누기"오류가 표시됩니다. 나는 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

'$ this-> FontSize'가 0으로 설정된 이유를 찾아서 고쳐 주십니까? BTW,'if' 문은'$ this-> FontSize'와 분리 된 변수 인'$ thisFontSize'에 대해 언급합니다. – paxdiablo

+0

고마워, 그 질문에 오타가 있었는데, 그것은 내 코드에서 맞습니다. 나는 그것을 위에 고칠 것이다. 그리고 네, 저는 운이없는 상태로 0으로 설정된 이유를 알아 내려고 노력했습니다. 나는 FPDF에 대한 더 많은 경험을 가진 누군가가 나를 계몽 할 수 있기를 희망한다. – Eckstein

+0

사용중인 WriteHTML 추가 기능에 대한 링크를 제공 할 수 있습니까? – TPete

답변

1

WriteHTML add-on은 원본 FPDF을 확장하는 PDF_HTML이라는 클래스입니다. 부가 기능을 사용하려면 당신은 그것을 서브 클래스를 인스턴스화하고 사용할 수 있습니다

$pdfhtml=new PDF_HTML(); 

당신은 부모 클래스의 추가 인스턴스 ($pdf)가 필요하지 않습니다. 를 제거하고 $pdfhtml$pdf의 모든 참조를 변경하고 당신은 갈 수 있습니다 : 나는 변경

<?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라고 부르는 라인을 주석 처리했다.

+0

완벽! 정말 고마워. FPDF는 여전히 나에게 약간의 수수께끼이지만, 당신의 대답은 나에게 약간의 통찰력을주었습니다 (더하기, 작동합니다!). 나는 렌더링 된 html이 어떤 스타일이나 서식으로도 표시되지 않는다는 것을 알았으므로이 작업을 더 잘 수행하는 방법을 살펴 보겠습니다.하지만 최소한 기능상의 문제는 해결되었습니다. – Eckstein

+0

아, 또한 SetDisplayMode가 실제로 설정되면 PDF의 기본보기가 문서의 실제 크기의 100 %에 있음을 의미합니다. 그것은 보이지만 그것은 잘 작동합니다. – Eckstein

+1

자, 그럼 * 실제 * 문자열 주위에 따옴표가 누락되었습니다. – TPete

0

pdf html에는 불균형이있을 수 있습니다. 일부 요소가 닫히지 않았거나 시작되지 않았을 수 있습니다. 이 문제를 찾으려면 2 일이 걸립니다.