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

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



// 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());

/*  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");

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

Return current item: Portable Programming Document