WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PDF class - This is a useful class to make a pdf file with php functions.
Categories : PHP, PDF, PHP Classes Click here to Update Your Picture
Diana Ortega
Date : Jun 09th 2003
Grade : 4 of 5 (graded 10 times)
Viewed : 20553
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Diana Ortega
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

To get it work you need the PDFlib that could be download from www.pdflib.com
In Unix you need to install the PDFlib and compile the php with PDFlib support.
In Windows you need to copy the pdflib.dll to the system32 folder.

<?php
class PDFFile
{
var
$pdf;
var
$FileName;
var
$Author;
var
$Creator;
var
$Subject;
var
$Title;
var
$font;
var
$file;
var
$xpos;
var
$xpos;
var
$pageSizeX;
var
$pageSizeY;


function
PDFFile(){
   
$this->pdf=pdf_new();
   
$this->FileName="";
   
$this->Author="";
   
$this->Creator="";
   
$this->Subject="";
   
$this->Title="";
   
$this->file="";
   
$this->pageSizeX=612;
   
$this->pageSizeY=792;
   
$this->font="Helvetica-Bold";
   
}

function
OpenPDF(){
//Opens a new pdf object
   
pdf_open_file($this->pdf);
   
$this->Data();
}

function
ClosePDF(){
//Closes a pdf document
   
pdf_close($this->pdf);
}

function
OpenPDFFile($path){
//Opens a new pdf document
   
$this->file = fopen($path,"w");
   
$this->pdf= PDF_open($this->file);
   
$this->Data();
}

function
SavePDFFile(){
//saves a pdf document
   
fclose($this->file);
}

function
Data(){
//Fills a field of the document information
   
pdf_set_info($this->pdf, "Author",$this->Author);
   
pdf_set_info($this->pdf, "Title",$this->Title);
   
pdf_set_info($this->pdf, "Creator",$this->Creator);
   
pdf_set_info($this->pdf, "Subject",$this->Subject);
}


function
ShowPDF(){
//Fetch the buffer containig the generated PDF data.
   
$this->file = pdf_get_buffer($this->pdf);
       
$this->SendToBrowser();     
       echo
$this->file;
}

function
SendToBrowser(){
       
header("Content-type: application/pdf");
       
header("Content-disposition: inline; filename=" . $this->filename);
       
header("Content-length: " . strlen($this->file));
}

function
StartPage(){
//Starts new page
   
pdf_begin_page($this->pdf, $this->pageSizeX, $this->pageSizeY);
}

function
ClosePage(){
//Ends a page
   
pdf_end_page($this->pdf);
}

function
Text($Text,$fontsize,$x,$y){
//Output text at given position ($x,$y)
   
$this->fontfunction($fontsize);
   
pdf_show_xy($this->pdf, $Text,($this->pageSizeX)-($x),($this->pageSizeY)-($y));
}

function
TextCont($Text,$ydist){
//Outputs text in next line
   
pdf_set_leading ($this->pdf,$ydist);
   
pdf_continue_text($this->pdf, $Text);
}

function
TextRend($num){
//Determines how text is rendered
   
PDF_set_text_rendering($this->pdf,$num);
}

function
SpacingChar($num){
//defines the space between characters
   
pdf_set_char_spacing ($this->pdf,$num); 
}

function
SpacingWord($num){
//defines the space between words
   
pdf_set_word_spacing ($this->pdf,$num);
}

function
fontwide($num){
//defines letters wide
   
pdf_set_horiz_scaling ($this->pdf,$num);
}

function
fontfunction($fontsize){
//defines font and fontsize
   
pdf_set_font($this->pdf,$this->font,$fontsize, "winansi");   
}

function
Line($x1,$y1,$x2,$y2){
//draws a line
//starting at point ($x1,$y1) and ending at pont ($x2,$y2)
   
pdf_moveto($this->pdf,$this->pageSizeX-$x1,$this->pageSizeY-$y1);
   
pdf_lineto($this->pdf,$this->pageSizeX-$x2,$this->pageSizeY-$y2);
   
pdf_stroke($this->pdf);
}

function
arc($x,$y,$radius,$angleStart,$angleend){
//Draws an arc
//with center at point ($x,$y) and radius $radius, starting at $anglestart and ending at $angleend.
   
pdf_arc($this->pdf,$this->pageSizeX-$x,$this->pageSizeY-$y,$radius,$angleStart,$angleend);
   
pdf_stroke($this->pdf);
}


function
Rectangle($x,$y,$xsize,$ysize){
//Draws a rectangle with its lower left corner at point ($x,$y)
//this width is set to $xsize and this height is set to $ysize
   
pdf_rect($this->pdf,$this->pageSizeX-$x,$this->pageSizeY-$y,$xsize,$ysize);   
   
pdf_stroke($this->pdf);
}

function
RoundRect($x,$y,$xsize, $ysize, $radius){
//Draws a rectangle with its lower left corner at point ($x,$y)
//this width is set to $xsize and this height is set to $ysize
//with a corners angle ($radius)
   
$xpos=$this->pageSizeX-$x;
   
$ypos=$this->pageSizeY-$y;
   
pdf_moveto($this->pdf, $xpos,$ypos-$radius);
   
pdf_lineto($this->pdf, $xpos,$ypos-$ysize+$radius);
   
pdf_arc($this->pdf, $xpos+$radius, $ypos-$ysize+$radius, $radius, 180, 270);
   
pdf_lineto($this->pdf, $xpos+$xsize-$radius, $ypos-$ysize);
   
pdf_arc($this->pdf, $xpos+$xsize-$radius, $ypos-$ysize+$radius, $radius, 270, 360);
   
pdf_lineto($this->pdf, $xpos+$xsize, $ypos-$radius);
   
pdf_arc($this->pdf, $xpos+$xsize-$radius, $ypos-$radius, $radius,0,90);
   
pdf_lineto($this->pdf, $xpos+$radius, $ypos);
   
pdf_arc($this->pdf, $xpos+$radius, $ypos-$radius, $radius,90,180);
   
pdf_stroke($this->pdf);   
}

function
Circle($x,$y,$radius){
//draws a circle
//with center at point ($x,$y) and radius $radius
   
pdf_circle ($this->pdf,$this->pageSizeX-$x,$this->pageSizeY-$y,$radius);
   
pdf_stroke($this->pdf);
}

function
rotate($xtranslate,$ytranslate,$numrot){
//sets the origin of coordinate system to the point ($xtranslate,$ytranslate) relativ the current
origin.
//and rotate the coordinate system by $numrot degrees.
   
$this->SavePdf();
   
$this->Translate($this->pdf, $xtranslate, $ytranslate); 
   
pdf_rotate($this->pdf, $numrot);
}

function
SavePdf(){
//Saves the current environment
//it is useful if you want to translate or rotate an object without effecting other objects.
   
pdf_save($this->pdf);
}

function
Translate($xTranslate, $ytranslate){
//sets the origin of coordinate system to the point ($xtranslate,$ytranslate) relativ the current
origin.
   
pdf_translate($this->pdf, $xTranslate, $ytranslate); 
}

function
Restore(){
//Restore the graphics state to the way it was
   
pdf_restore($this->pdf);
}


function
OpenJpg($path,$x,$y,$scale){
//opens a Jpg image
//places an image on the page at postion ($x,$y) and scaled ($scale)
   
$pdfimage = pdf_open_image_file($this->pdf, "jpeg", $path);
   
PDF_place_image($this->pdf,$pdfimage,$this->pageSizeX-$x,$this->pageSizeY-$y,$scale);
}

function
OpenTiff($path,$x,$y,$scale){
//open a tiff image
//places an image on the page at postion ($x,$y) and scaled ($scale)
   
$pdfimage = pdf_open_image_file($this->pdf, "tiff", $path);
   
PDF_place_image($this->pdf,$pdfimage,$this->pageSizeX-$x,$this->pageSizeY-$y,$scale);
}

function
Opengif($path,$x,$y,$scale){
//open a Gif image
//places an image on the page at postion ($x,$y) and scaled ($scale)
   
$pdfimage = pdf_open_image_file($this->pdf, "gif", $path);
   
PDF_place_image($this->pdf,$pdfimage,$this->pageSizeX-$x,$this->pageSizeY-$y,$scale);
}

function
OpenPng($path,$x,$y,$scale){
//open a Png image
//places an image on the page at postion ($x,$y) and scaled ($scale)
   
$pdfimage = pdf_open_image_file($this->pdf, "png", $path);
   
PDF_place_image($this->pdf,$pdfimage,$this->pageSizeX-$x,$this->pageSizeY-$y,$scale);
}


}
//end of class


/* lets see an example */
//instance a new pdf object
$pdf = new PDFFile;

//Fills the document information
$pdf->Filename="ExampleFileName";
$pdf->Author="Diana Ortega";
$pdf->Title="ExampleTitle";
$pdf->Creator="Diana Ortega";
$pdf->Subject="PDFExample";


//Opens the new pdf object
$pdf->openPDF();

//starts the first page
$pdf->BOF();

//draw a rectangle with its lower left corner at point   ('pageSizeX->612'-300,'pageSizeY->792'-300)
//and its width is 200 and height is 250
$pdf->rectangle(300,300,200,250);


//Output text at given position ('pageSizeX->612'-400,'pageSizeY->792'-400)
//and its fontsize is 15
$pdf->Text("HELLO1",15,400,400);

//output the text 30 coordinates bellow
$pdf->TextCont("HELLO2",30);

//change the parameter for this text
$pdf->TextRend(2);
$pdf->spacingchar(25);
$pdf->spacingword(35);
$pdf->fontwide(80);
$pdf->Text("Hello :)",15,450,400);

//Draws an arc
//with center at point ('pageSizeX->612'-500,'pageSizeY->792'-500)
/and radius 50, starting at angle 90 and ending at 180
$pdf
->arc(500,500,50,90,180);


//draws a circle
//at the point ('pageSizeX->612'-400,'pageSizeY->792'-400)
$pdf->circle(400,400,25);

//End of page
$pdf->EOF();

//Closes the pdf document
$pdf->closePDF();

//Show in window the PDF document
$pdf->Showpdf();

?>


The result should be a PDF file with the indicated draws.



Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
How To Create a PDF Using PHP
Categories : PHP, PDF, PHP Classes, HTML and PHP
Url To Pdf Report By Remote Application
Categories : PHP, PHP Classes, PDF, CURL
Generate FDF files without the pdftk library or php extension.
Categories : PHP, PHP Classes, PDF
Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented
Gonx Proxy - This class is meant to act as an HTTP proxy to serve pages of a remote server as if they were local pages.
Categories : PHP, PHP Classes, HTTP
This is a class with functions that are taken from simple SQL statements. I made it to have an easier connection between PHP3 and DBase files.
Categories : General SQL, PHP, PHP Classes, Databases
MS Word Mail Merge Automation (COM)
Categories : PHP, PHP Classes, COM
Very minimal templating engine
Categories : PHP, PHP Classes, Templates
a class that uses microtime() to provide easy calculation of elapsed times
Categories : Date Time, PHP, PHP Classes
base64 with encryption - encode and decode sessions
Categories : PHP, PHP Classes, Encryption, Sessions
Class TStringList include some metods from class TStringList implemented in INPRISE/BORLAND-DELPHI
Categories : PHP Classes, PHP, Strings
Use of bitmasks to represent permissions
Categories : PHP, Authentication, Bitwise Operators, Security, PHP Classes
A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP
XPertMailer - Sends TRUE Mails
Categories : PHP, Mail, SMTP, PHP Classes
 matthew waygood wrote : 978
PDFlib licence is US$450 - to have the DEMO removed from your creations.

So I don`t think I would ever get to use your example.

Perhaps an example using the FPDF class from http://www.fpdf.org would be better (ITS FREE, SMALLER AND DOESNT REQUIRE INSTALLATION).
 
 Indeo Indeo wrote : 1029
Fatal error: Call to undefined function: bof() in g:\usr\krasnal\www\test\pdf.php on line 255
 
 David Perez wrote : 1031
The PDFlib lite is for free, it comes in the ports install from FreeBSD
 
 Selvakumar Thangavelu wrote :1873
i got error.
Check the 13 th Line: var $xpos; It will change to var $ypos;
and I got error "Fatal error: Call to undefined function PDF_open() in C:\Server\apache\htdocs\pdflib\index.php on line 46"