Login   Register  
PHP Classes
elePHPant
Icontem

File: gen_pdf.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jon Lawrence  >  Portable Programming Document  >  gen_pdf.php  >  Download  
File: gen_pdf.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Portable Programming Document
Generate highlighted PDF documents from PHP code
Author: By
Last change:
Date: 9 years ago
Size: 1,175 bytes
 

Contents

Class file image Download
<?php


require_once 'php_pdf.class.php';

//The file name that is going to be converted into a PDF document.
$fileName "php_pdf.class.php";

//Create the new PHP->PDF object
$pdf_doc = new PHP_PDF();

//Set the header to the filename so that when it is opened it can be distinguished as to what it is.
$pdf_doc->setHeader($fileName);

//Load the filename and use line number.
/* to not show line numbers, this would be called as...

$pdf_doc->loadFile($fileName,false);
*/

$pdf_doc->loadFile($fileName);

// Now we will write the pdf file to the same file name with the added "pdf" extension
$hand fopen("{$fileName}.pdf""wb");
//  "$pdf_doc->getPDF()" will retrieve the generated PDF that is in memory.
fwrite($hand$pdf_doc->getPDF());
fclose($hand);


/*  That is how you would arbitrarily load from a php file.
   If you want to use code that user inputs, the following meathod is used.
*/

// load PHP source code
$code "<?php\necho \"this is a test code sample\";\n?>";


$pdf_doc = new PHP_PDF();
$pdf_doc->setHeader("User-generated Code");
$pdf_doc->loadText($code);

$hand fopen("test.pdf""wb");
fwrite($hand$pdf_doc->getPDF());
fclose($hand);



?>