WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
PHP Web Logs (BLogs)
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
Submit Site
Forex Trading Online forex trading platform

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 : Free PDF file creation using PHP.
Categories : PDF, PHP Click here to Update Your Picture
Srikanth Turaga
Date : Aug 09th 2003
Grade : 3 of 5 (graded 16 times)
Viewed : 21211
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Srikanth Turaga
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

Hi friends,

I am posting the code of creating PDF files using PHP. You can use the PDF Lib that comes with the PHP, but then you have to pay them to create PDF files without their ads on them. Here is the code and links that would allow you to create your own PDF files without any ads on them and without paying a single cent to them.

The PDF lib is available at http://www.fpdf.org/. You can download the ZIP or TGZ files from this site and open them in any directory.

All you need to do is Define the font in your code and include the fpdf.php file into your code.

Below is a short code that helps you create a sample PDF file. Creating PDF file helps a lot in generating reports for the database transactions or creating downloadable question papers for online quizzes etc, etc.

This code works perfectly when I tested it.
Code follows:
HTML file to create PDF file.

<HTML>
<BODY>
<FORM method = "post" action ="pdfdemo.php">
<BR><INPUT TYPE=Submit name=Submit VALUE = "Create PDF">
</FORM>
</BODY>
</HTML>


PHP code that generates the PDF file.

<?php
define('FPDF_FONTPATH','/yourdirectorywhereFPDFisstored/FPDF/font/');
require('/yourdirectorywhereFPDFisstored/FPDF/fpdf.php');
class PDF extends FPDF
{
function DashedRect($x1,$y1,$x2,$y2,$width=1,$nb=15)
{
$this->SetLineWidth($width);
$longueur=abs($x1-$x2);
$hauteur=abs($y1-$y2);
if($longueur>$hauteur) {
$Pointilles=($longueur/$nb)/2; // length of dashes
}
else {
$Pointilles=($hauteur/$nb)/2;
}
for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) {
for($j=$i;$j<=($i+$Pointilles);$j++) {
if($j<=($x2-1)) {
$this->Line($j,$y1,$j+1,$y1); // upper dashes
$this->Line($j,$y2,$j+1,$y2); // lower dashes
}
}
}
for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) {
for($j=$i;$j<=($i+$Pointilles);$j++) {
if($j<=($y2-1)) {
$this->Line($x1,$j,$x1,$j+1); // left dashes
$this->Line($x2,$j,$x2,$j+1); // right dashes
}
}
}
}
}

$pdf=new PDF();
$pdf->Open();
$pdf->AddPage();
$pdf->SetDrawColor(200);
$pdf->DashedRect(20,10,190,40);
$pdf->SetFont('Arial','B',20);
$pdf->SetXY(40,10);
$pdf->Cell(125,30,'Congrats! You created your first PDF file.',0,0,'C',0);
$pdf->Output();
?>

You can find the tutorials and API references at http://www.fpdf.org/. If I remember my example
code is took from the tutorials posted at http://www.fpdf.org/.

Hope this helps some one. Please let me know if there is some problem with the code. I'll be glad
to help you.

Thank you,
Sri.



Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
PDF class - This is a useful class to make a pdf file with php functions.
Categories : PHP, PDF, PHP Classes
How To Create a PDF Using PHP
Categories : PHP, PDF, PHP Classes, HTML and PHP
PDF_add_annotation -- Deprecitad: Adds annotation
Categories : PHP, PHP Functions, PDF
PHP-PDF-Converter
Categories : PHP, Excel, PDF, Microsoft Word, COM
Url To Pdf Report By Remote Application
Categories : PHP, PHP Classes, PDF, CURL
Retrieve text from table and email to your e- address in pipe delimited format.
Categories : PHP, MySQL
Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs.
Categories : Databases, PHP, MySQL, Complete Programs
A PHP function to encrypt and decrypt a number or string or a combination of the two.
Categories : PHP, Encryption, Security
Using $PHP_AUTH_USER and $PHP_AUTH_PW to authenticate.
Categories : Authentication, PHP
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways
Cut your MySQL Connections to 1 line of code
Categories : PHP, Beginner Guides, Databases, MySQL
Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality.
Categories : PHP, GD image library, Graphics
readline -- Reads a line
Categories : PHP, PHP Functions, Readline
 Marianne Mason wrote :1011
thank you.  This was a timely post as I`ve been given an assignment to upload documents and convert to pdf.