Generating a PDF document-PHP



Generating a PDF document
<?php
// These values are in points (1/72nd of an inch)

$fontsize = 72;     // 1 inch high letters

$page_height = 612; // 8.5 inch high page

$page_width = 792;  // 11 inch wide page



// Use a default message if none is supplied

if (strlen(trim($_GET['message']))) {

    $message = trim($_GET['message']);

} else {

    $message = 'Generate a PDF!';

}



// Create a new PDF document in memory

$pdf = pdf_new( );

pdf_open_file($pdf, '');



// Add a 11"x8.5" page to the document

pdf_begin_page($pdf, $page_width, $page_height);



// Select the Helvetica font at 72 points

$font = pdf_findfont($pdf, "Helvetica", "winansi", 0);

pdf_setfont($pdf, $font, $fontsize);



// Display the message centered on the page

pdf_show_boxed($pdf, $message, 0, ($page_height-$fontsize)/2,

               $page_width, $fontsize, 'center');



// End the page and the document

pdf_end_page($pdf);

pdf_close($pdf);



// Get the contents of the document and delete it from memory

$pdf_doc = pdf_get_buffer($pdf);

pdf_delete($pdf);



// Send appropriate headers and the document contents

header('Content-Type: application/pdf');

header('Content-Length: ' . strlen($pdf_doc));

print $pdf_doc;
 
?>
the functions in the PDF extension. 
This extension depends on the PDFLib 
library that is available at
 http://www.pdflibrary.com
The CLibPDF extension also generates
 PDF files, 
Related Posts:
  • Improved Array-HandlingPHP PHP  offers a plethora of new functions for accessing and manipulating arrays. These functions include, but are not limited to, array_splice(), array_push(), array_pop(), and array_diff(). Integrated Sessions&n… Read More
  • Generating a PDF document-PHP Generating a PDF document <?php // These values are in points (1/72nd of an inch) $fontsize = 72; // 1 inch high letters $page_height = 612; // 8.5 inch high page $page_width = 792; // 11 inch wide page … Read More
  • How to create a thumbnail-PHP code To create a thumbnail, you pass the function PIPHP_MakeThumbnail()a GD image object and the maximum value of the greater dimension for the thumbnail. For example, the following code loads in the image in test.jpgusing the … Read More
  • PHP-HTTP and Sessions-Maintaining State HTTP has no mechanism to maintain state; thus HTTP is a context-free or stateless protocol. Individual requests aren't related to each other. The Web server and thus PHP can't easily distinguish between single users and… Read More
  • CodeIgniter system Folder The system/ folder is where all the action happens. This folder contains all the CodeIgniter code of consequence, organized into various folders: application —  The   application foldercontains the applicat… Read More
  • PHP Online Resources The major sites that use PHP, and a listing of all the books written on PHP. Not only does this site contain a plethora of resources, it also contains links to the other PHP sites, the latest news about all things PHP … Read More
  • PHP-Mail Functions PHP contains two dedicated mail functions, which are built into PHP by default. The mail() function allows for the sending of email directly from a script, and ezmlm_hash() provides a hash calculation useful for interf… Read More
  • PHP-Http Environment Variables A Web browser makes a request of a Web server, it sends along with  the request a list of extra variables. These are called environment  variables, and they can be very useful for displaying dynamic content or… Read More
  • CodeIgniter config.php The  config.php filecontains a series of configuration options all of them stored in a PHP array called, appropriately enough, $config) that CodeIgniter uses to keep track of your application ’ s  information and… Read More
  • What is an array? An array is a variablethat stores more than onepiece of related data in a single variable. Thinkof an array as a box of chocolateswith slotsinside. The box representsthe arrayitself whilethe spacescontaining chocolates rep… Read More
  • website-secure-PHP Cryptography is the process of changing the format of data (i.e., encrypting it) so that it is more difficult to read. Some cryptography, such as PGP, available for free for public use from http://www.pgp.com,  use… Read More
  • free php script-download free php scripts | Open Source PHP - PHP Scripts gscripts.net/ A directory of free php scripts such as forums, photo galleries, CMS, and e-commerce solutions. Each script has demo so it can be tested prior to download… Read More
  • PHP and Javascript Variables Variables To define a variable in PHP, you’d write:// PHP$n = 1;The equivalent in JavaScript is:// JavaScriptvar n = 1; There’s no dollar sign, just the name of the variable.  Like in PHP, you don’t define variable… Read More
  • PHP-Array Functions -list(),each(), and count(). list() is sort of an operator, forming an lvalue (a value that can be used on the left side of an expression) out of a set of variables, which represents itself as a new entity similar to an element of a multidimension… Read More
  • Program Yahoo! with PHP 5 Take advantage of some of the latest features in PHP to quickly add Yahoo! data to PHP-powered pages. The recursively named PHP Hypertext Processor language is a popular choice for building dynamic web applications. In… Read More