PHP Classes

File: gen_pdf.php

Recommend this page to a friend!
  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: 19 years ago
Size: 1,175 bytes


Class file image Download

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