Location: PHPKode > scripts > Portable Programming Document > portable-programming-document/gen_pdf.php
<?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);



?>
Return current item: Portable Programming Document