We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21560
    • 145 Posts
    Well, the base is fairly simple. The more difficult things are formatting. As I use a very basic form of FPDF, there is practically no formatting besides lines/paragraphs.

    Read the last 5 posts or so to see an alternative. Unfortunately I haven’t had the time to integrate and test it myself... yet.
      [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
      • 16545
      • 358 Posts
      I’ve got an error:

      PHP error debug
      Error: FPDF::include(helveticai.php) [fpdf.include]: failed to open stream: No such file or directory
      Error type/ Nr.: Warning - 2
      File: C:\xampp\php\PEAR\fpdf.php
      Line: 550
      Line 550 source: include($this->_getfontpath().$file.’.php’);

      Is it problem of XAMP Windows version?
      • That means it’s not included with your version apparently.

        No such file or directory
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 16085
          • 203 Posts
          I’ve got a couple of issues, although not spent enough time digg’in..

          I’ve followed the install and everything seems to be fine. Used the snippet code from page 1 rather then the one from the zip file.

          Looked through the posts and found someone else who wanted to generate a PDF from the current page there on. So I added the code changes from page 4 added $parent = $_GET[’documentid’]; to the start of the snippet.

          I then create a new document, blank template with the call [!MakePDF? &parent=`1` &filename=`test.pdf`!]. Then used the a href link for the Get PDF <a href="[~14~]?documentid=[*id*]">Get PDF</a>

          Now it all works except, the PDF outputs the html of the page and even if I set &filename=`test.pdf` it still giving me ’Frozen_Youth.pdf’ default with the frozen youth copyright footerr.

          Help!?
            • 21560
            • 145 Posts
            Check the header/footer addition to the class and/or remove it. It’s the bit below. You can safely delete those two functions, but it is of course even better to change the text in that to something more preferable. I could have made them snippet variables, but time is not always in my favor wink

            		function Header()
            		{
            		    $this->SetFont('Arial','I',11);
            		    //Position at 1.5 cm from bottom
            		    $this->SetY(5);
            		    //Page number
            		    $this->Cell(0,10,'Frozen Youth',0,1,'R');
            		}
            		function Footer()
            		{
            		    $this->SetFont('Arial','I',8);
            		    //Position at 1.5 cm from bottom
            		    $this->SetY(-15);
            		    //Page number
            		    $this->Cell(0,10,'Copyright 2007-2008 - Nimja.com',0,0,'L');
            		    //Position at 1.5 cm from bottom
            		    $this->SetY(-15);
            		    //Page number
            		    $this->Cell(0,10,$this->PageNo(),0,0,'R');
            		}


            Also, the filename is set through:

            $filename = (!empty($filename) ) ? $filename : 'Frozen_Youth.pdf';


            You can edit it there as, for some reason, it’s not picking up your filename in the snippet call. I don’t see any ’errors’ immediately but check it out there.
              [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
              • 16085
              • 203 Posts
              @Nimja, thanks for the reply. I appreciate your efforts! I’ve removed Header and Footer Class code leaving me with this code;

              <?php
              /* MakePDF snippet:
              
              v0.7 - Fixed the 'depcrecated' error that prevented PDFs from being proper.
              v0.6 - Added multiple parents support.
              v0.5 - Italic font support, limited to whole lines/paragraphs.
              v0.4 - Optimizations for 100+ pages.
              v0.3 - Added header and footer.
              v0.2 - Numerous fixes
              v0.1 - Basic work.
              
              By Nimja - nimja.com
              
              Usage:
               [!MakePDF? &parent=`1` !] -- Basic example
               [!MakePDF? &parent=`1,2,3` !]  -- Multiple parents
               [!MakePDF? &parent=`1` &sortBy=`pub_date` $sortDir=`asc` &where=`template=1` &filename=`Frozen_Youth.pdf` &limit=`10`!] -- Additional settings.
               
              */
              
              
              /* ------------------------------------------
              			Basic settings
              ------------------------------------------- */
              $parent = $_GET['documentid'];
              
              if (isset($parent)) {
              	
              	// &sortBY, field to sort by, defaults to pub_date.
              	$sortBy = (!empty($sortBy) ) ? $sortBy : 'menuindex';
              	
              	// &sortHow, sort direction, defaults to ASC(ending).
              	//	Options are: ASC, DESC
              	$sortHow = (!empty($sortHow) ) ? $sortHow : 'ASC';
              	
              	//Additional 'filters'
              	$where = (!empty($where) ) ? $where : '';
              
              	//&filename - The filename of the PDF people will download.
              	$filename = (!empty($filename) ) ? $filename : 'Frozen_Youth.pdf';
              
              	//&limit - Max number of pages we will retrieve. Leave empty or 0 for all.
              	$limit = (!empty($limit) ) ? $limit : '';
              	
              	//Fields we use.
              	$fields = 'longtitle,description,content';
              	
              	$basepath = $modx->config['base_path']."assets/snippets/makepdf/";
              	$classpath = $basepath.'class/';
              
              
              	//Use MODX function to get documents
              	$parents = split(',', $parent);
              	$pages = Array();
              	foreach($parents as $par) {
              		$page = $modx->getDocument($par, $fields, 1, 0);
              		array_push($pages, $page);
              	}
              
              /* ------------------------------------------
              			Start PDF and set the settings.
              ------------------------------------------- */
              
              	// initiate FPDI 
              	$pdf = new PDF(); 
              	// add a page 
              	$pdf->AddPage(); 
              	// set the sourcefile 
              	$pdf->setSourceFile($basepath.'Page.pdf'); 
              	$pdf->SetAuthor('Nimja');
              	$pdf->SetCreator('Nimja');
              	$pdf->SetTitle('Frozen Youth');
              	
              	// import page 1 
              	$templatePage = $pdf->importPage(1); 
              	// use the imported page and place it on the first page. After this it will be added to every page.
              	$pdf->useTemplate($templatePage);
              	// set the template to be applied automatically.
              	$pdf->setTemplate($templatePage); 
              
              	$pdf->SetFont('Arial'); 
              	$pdf->SetTextColor(0,0,0); 
              	$pdf->SetLineWidth(.25);
              	$pdf->SetDrawColor(0,0,0);
              	$pdf->SetMargins(10,10);
              	
              	$newpage = false;
              
              	$remove = Array("\r", '<b>', '</b>');
              	$clean = Array('<i>', '</i>');
              
              
              /* ------------------------------------------
              			Start content.
              ------------------------------------------- */
              
              	$c = 0;
              	$italic = false;
              	foreach ($pages as $page) {
              		//echo $page['longtitle'].' - '.$page['introtext'].'<br />';
              		$chapter = $page['longtitle'];
              		$title = $page['description'];
              		$content = str_replace($remove, '', $page['content']);
              		
              		//Start at the top of a page after 10 chapters. Because I'm base-10 addicted.
              		if ($c > 9) {
              			$pdf->AddPage();
              			$c=0;
              		}
              
              		//Set the title.
              		$pdf->SetX(10);
              		$pdf->SetFont('Arial','',18);
              		$pdf->Cell(0,7,$chapter.' - '.$title,'B',1,'L');
              
              		//Add some space between the title and the content.
              		$pdf->Ln(3);
              
              		$content = split("\n", $content);
              
              		//Handle content per line/block.		
              		foreach ($content as $par) {
              			$line = trim($par);
              
              			//Space between paragraphs (a little less than a whole line, looks nicer).
              			if (empty($line) ) {
              				$pdf->Ln(3);
              				
              			} else {
              				if (strpos($line, '<i>') > -1) $italic = true;
              
              				//Switch between italic and normal. Only usable for whole paragraphs/lines for now.
              				if ($italic) {
              					$pdf->SetFont('Arial','i',11);
              				} else {
              					$pdf->SetFont('Arial','',11);
              				}
              				if (strpos($line, '</i>')) $italic = false;
              				
              				$line = str_replace($clean, '', $line);
              				$pdf->MultiCell(0,4.5,$line,0,1,'L');
              			}
              		}
              		$pdf->Ln(10);
              		$italic = false;
              		$c++;
              	}
              
              	$pdf->Output('Frozen_Youth.pdf', 'd'); 
              	
              } else {
              	//Output error message because of missing parent ID
              	echo 'Parent ID missing!';
              }
              ?>


              but I’m getting: Fatal error: Class ’PDF’ not found in /home/demolip/public_html/manager/includes/document.parser.class.inc.php(769) : eval()’d code on line 65

                • 21560
                • 145 Posts
                Naturally, as you removed the whole class that extended FPDI ^_^

                class PDF extends FPDI {


                This means that we ’write’ the header and footer functions in a new PDF class over an already existing class called FDPI. TO solve this, simply replace new PDF(); by new PDFI();

                That’s all.

                	// initiate FPDI 
                	$pdf = new PDFI(); 


                ps. Sorry for the really late reply, had a week holiday. wink
                  [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
                  • 16085
                  • 203 Posts
                  Okay got it sorted a bit more, RTM’in the FPDF and FPDI. On page PDF generate is working using the $_GET docid but my page was rendering <p>, <strong>, &nbsp tags.. Didn’t realise you need to add them to the $remove list. However according to FPDF I need to use HTMLDOC to convert my pages to pdf, unless I strip out everything in the $remove variable.

                  Others I found in this thread but not tried yet.
                  PDML
                  TCPDF
                    • 21560
                    • 145 Posts
                    TCPDF is what I want to look at myself as well. The reason why I still use the ’old’ FPDF is because it’s the only PHP -> PDF library that supports 50+ pages.

                    (I’ve got a document with 450 pages)
                      [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
                    • TCPDF looks very nice indeed. Supporting CMYK color space and Adobe Illustrator files is very nice, amongst others.
                        Ryan Thrash, MODX Co-Founder
                        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me