Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.3.3

Bug #12310 Invalid output
Submitted: 2007-10-23 08:28 UTC
From: garivin Assigned: yunosh
Status: Closed Package: File_PDF (version 0.3.0)
PHP Version: 5.2.3 OS: Windows XP
Roadmaps: (Not assigned)    

 [2007-10-23 08:28 UTC] garivin (Javier Mestre)
Description: ------------ setTextColor and setFillColor ,addPage and cell problems Test script: --------------- This script tuto3.php is copied from tutorials of FPDF package ( <?php //ini_set("include_path", 'C:/Proyectos PHP/Pear/' . PATH_SEPARATOR . ini_get("include_path")); require('File/PDF.php'); class MyPDF extends File_PDF { function header() { global $title; //Arial bold 15 $this->setFont('Arial','B',15); //Calculamos ancho y posici¾n del tÝtulo. $w=$this->GetStringWidth($title)+6; $this->setX((210-$w)/2); //Colores de los bordes, fondo y texto $this->setDrawColor("rgb",0/255,80/255,180/255); $this->setFillColor("rgb",230/255,230/255,0/255); $this->setTextColor("rgb",220/255,50/255,50/255); //Ancho del borde (1 mm) $this->setLineWidth(1); //TÝtulo $this->cell($w,9,$title,1,1,'C',1); //Salto de lÝnea $this->newLine(10); } function footer() { //Posici¾n a 1,5 cm del final $this->setY(-15); //Arial itßlica 8 $this->setFont('Arial','I',8); //Color del texto en gris $this->setTextColor(128); //N·mero de pßgina $this->cell(0,10,'Pßgina '.$this->getPageNo(),0,0,'C'); } function ChapterTitle($num,$label) { //Arial 12 $this->setFont('Arial','',12); //Color de fondo $this->setFillColor("rgb",200/255,220/255,255/255); //TÝtulo $this->cell(0,6,"CapÝtulo $num : $label",0,1,'L',1); //Salto de lÝnea $this->newLine(4); } function ChapterBody($file) { //Leemos el fichero $f=fopen($file,'r'); $txt=fread($f,filesize($file)); fclose($f); //Times 12 $this->setFont('Times','',12); //Imprimimos el texto justificado $this->multiCell(0,5,$txt); //Salto de lÝnea $this->newLine(); //Cita en itßlica $this->setFont('','I'); $this->cell(0,5,'(fin del extracto)'); } function PrintChapter($num,$title,$file) { $this->addPage(); $this->ChapterTitle($num,$title); $this->ChapterBody($file); } } $pdf=& MyPDF::factory(array('orientation' => 'P','unit' => 'mm','format' => 'A4'),"MyPDF"); $title='20000 Leagues Under the Seas'; $pdf->setInfo("title",$title); $pdf->setInfo("author","Jules Verne"); $pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt'); $pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt'); $pdf->Output('',true); ?> Expected result: ---------------- Same output with both PDF generators. Actual result: -------------- 1.- The blue rectangle with the title of the page is filled in red (text color). 2.- The second page is written with the footer font 3.- The footer test is centered in the first page but on the left in the second one. Solutions found: 1.- Comment in setTextColor if ($this->_page > 0) { // $this->_out($this->_text_color); <--- } 2.- In addPage move $font_family=$this->_font_family; $font_style=$this->_font_style.($this->_underline ? 'U' : ''); $font_size = $this->_font_size_pt; just after $this->_beginDoc() line comment line: /* Set font for the beginning of the page. */ // $font_family = null; <-- 3.- ¿?


 [2007-10-23 19:21 UTC] garivin (Javier Mestre)
Sorry, the output on the footer in the second page is on the RIGHT.
 [2007-11-07 16:54 UTC] yunosh (Jan Schneider)
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at
 [2007-11-08 12:40 UTC] garivin (Javier Mestre)
Using the same script, the colors and footer problems are solved but the font problem with the second (and following pages) of each chaper writen with the footer font still persist. More info, if you add "$this->setTextColor("rgb",255/255,0/255,255/255);" to the footer function and $this->setTextColor("rgb",0/255,255/255,0/255); to the ChaperBody function the footer text prints violet this color but the text in the next page body is printed in green (all the pages) If you mofify the addPage function as follows /* For good measure make sure this is called. */ $this->_beginDoc(); //<JMS> $font_family=$this->_font_family; $font_style=$this->_font_style.($this->_underline ? 'U' : ''); $font_size = $this->_font_size_pt; //</JMS> and /* Set font for the beginning of the page. */ // $font_family = null; if ($this->_font_family) { // $font_family = $this->_font_family; // $font_style = $this->_font_style . ($this->_underline ? 'U' : ''); // $font_size = $this->_font_size_pt; $result = $this->setFont($font_family, $font_style, $font_size); if (is_a($result, 'PEAR_Error')) { return $result; } } seems that it works as expected
 [2007-11-08 14:54 UTC] yunosh (Jan Schneider)
Your script didn't work at all actually. See the fixed version in tests/pear12310.phpt which creates a perfectly correct PDF file.
 [2007-11-08 21:08 UTC] garivin (Javier Mestre)
I have tested your code and it works as expected, perhaps the problem is my poor english. Let me explain again my problem. In the FPDF ( tutorials page, the tutorial 3 outputs 4 pages ,pages 1 and 2 in the first chapter (file 20k_c1.txt) and pages 3 and 4 in the second one (file 20k_c2.txt). If you look at the tutorial demo all the pages are in Times Roman. Using you code and changing the ChapterBody function to read from the file function ChapterBody($file) { //Read text file $f=fopen($file,'r'); $txt=fread($f,filesize($file)); fclose($f); //Times 12 $this->setFont('Times','',12); //Output justified text // $this->multiCell(0,5,$file); <------------ $this->multiCell(0,5,$txt); <------------ //Line break $this->newLine(); //Mention in italics $this->setFont('','I'); $this->cell(0,5,'(end of excerpt)'); } And $pdf->printChapter(1, 'A RUNAWAY REEF', '20k_c1.txt'); $pdf->printChapter(2, 'THE PROS AND CONS', '20k_c2.txt'); what I have is a PDF file with page 1 (the first in the first chapter) OK , page 2 (the second in the first chaper) writen with the footer font, page 3 (the first in the second chapter) OK and page 4 again bad I can send all the files if needed
 [2007-11-08 23:33 UTC] yunosh (Jan Schneider)
Ah, so this only happens if the text included is longer than a page? Can you point me to the example that you used? I couldn't find it on
 [2007-11-09 16:28 UTC] garivin (Javier Mestre)
Files sent directly to yunosh (Thanks Jan)
 [2007-11-09 17:36 UTC] yunosh (Jan Schneider)
You can of course work around this easily by resetting the font after writing the footer, e.g. add the following lines to the end of the footer() method: $this->setFont('Times', '', 12); $this->setTextColor('gray', 1);
 [2007-11-14 19:37 UTC] yunosh (Jan Schneider)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.