IT Community - Software Programming, Web Development and Technical Support

PDF Creating in PHP

This is a discussion on PDF Creating in PHP within the PHP Programming forums, part of the Web Development category; pdf files are very useful for data reporting. bcoz now every system having a pdf file reader. The PDF functions ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-25-2008, 04:22 AM
saravanan saravanan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 181
saravanan is on a distinguished road
Default PDF Creating in PHP

pdf files are very useful for data reporting. bcoz now every system having a pdf file reader.

The PDF functions in PHP can create PDF files using the PDFlib library created by Thomas Merz.

All of the functions in PDFlib and the PHP module have identical function names and parameters

Last edited by saravanan : 03-26-2008 at 03:56 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-26-2008, 03:49 AM
sureshbabu sureshbabu is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Location: India
Posts: 101
sureshbabu is on a distinguished road
Send a message via AIM to sureshbabu Send a message via MSN to sureshbabu Send a message via Yahoo to sureshbabu Send a message via Skype™ to sureshbabu
Default Re: PDF Creating in PHP

what is the requirement for creating pdf file
__________________
Thanks
Regards
Sureshbabu Harikrishnan
+91 9884320017

Last edited by sureshbabu : 03-26-2008 at 03:57 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-27-2008, 07:44 AM
sureshbabu sureshbabu is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Location: India
Posts: 101
sureshbabu is on a distinguished road
Send a message via AIM to sureshbabu Send a message via MSN to sureshbabu Send a message via Yahoo to sureshbabu Send a message via Skype™ to sureshbabu
Default Re: PDF Creating in PHP

how to align tables in pdf files
__________________
Thanks
Regards
Sureshbabu Harikrishnan
+91 9884320017
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-28-2008, 03:59 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

Quote:
Originally Posted by sureshbabu View Post
what is the requirement for creating pdf file
Using HTML2PDF we can able to convert html page to pdf.

HTML2PDF is a simple HTML to PDF tool which can quickly and easily convert thousands of HTML pages into PDF reports.
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-28-2008, 04:02 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

HTML2PDF (include PDFcamp + DocConverter COM) is the easiest way to convert your web pages and DOC, RTF, TXT, PPT, XLS files into PDF documents, HTML2PDF quickly and accurately transforms well-formed HTML, DOC, RTF, TXT, PPT, XLS files into PDF files, the HTML2PDF supports both server and client sides, the end-user doesn't need any software (Adobe Acrobat and Reader NOT required).

HTML2PDF (include PDFcamp + DocConverter COM) offers you the flexibility and speed you need to convert multiple HTML, DOC, RTF, TXT, PPT, XLS files into PDF format. Whatever the reason, pdf files can be created directly from MS Internet Explorer (or at background) and even emailed to a recipient/recipients simultaneously.
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-28-2008, 04:04 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

HTML2PDF Features:

* HTML2PDF can create page headers, footers and page numbers
* HTML2PDF can convert HTML, DOC, RTF, TXT, PPT, XLS files to PDF files on the fly
* HTML2PDF supports adjust paper orientation and size to accommodate HTML documents
* HTML2PDF supports nested tables
* HTML2PDF supports all elements in HTML document, include asp, cgi, css, Java Applets, flash, cookie etc.
* HTML2PDF supports dynamic page breaks with headers and footers
* HTML2PDF supports convert a URL or local file to PDF file
* HTML2PDF can convert .doc/.html/.rtf/.txt/.xls etc files to PDF files from a Command Line Tool, this Tool without any user intervention
* HTML2PDF supports command line operation (for manual use or inclusion in scripts)
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-28-2008, 04:21 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

How convert a HTML, DOC, RTF, TXT, PPT, XLS files to PDF files with DocConverter COM?

Step 1:
Please download and install the PDFcamp (PDF Writer) software,
http://www.verypdf.com/pdfcamp/pdfcamp_setup.exe
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 03-28-2008, 04:22 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

Step 2:

Please download and register the DocConverter COM software,
http://www.toppdf.com/pdfcamp/doc2pdf_com_trial.zip
Please register the pdfout.dll file in your system, for example,
~~~~~~~~~~~
regsvr32 pdfout.dll
~~~~~~~~~~~
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 03-28-2008, 04:24 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

Step 3:

Please run the html2pdf.exe software from the Command Line Window to try, the html2pdf.exe software is included in the DocConverter COM package,

For example:

html2pdf.exe "http://www.yahoo.com" "c:\yahoo.pdf"
html2pdf.exe "http://www.google.com/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=pdf" "c:\google.pdf"
html2pdf.exe "C:\example.doc" "C:\example.pdf"
html2pdf.exe "C:\example.xls" "C:\example.pdf"
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 03-28-2008, 04:25 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

Step 4:

Now You have converted HTML, DOC, RTF, TXT, PPT, XLS files to PDF documents.
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 03-28-2008, 04:27 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

Step 5:
Now, you can call the html2pdf.exe software from your Delphi, C++, VB, BCB etc. applications.

HTML2PDF - Converting your HTML, DOC, RTF, TXT, PPT, XLS files to PDFs has never been easier! Combine several of your HTML, DOC, RTF, TXT, PPT, XLS files into a single PDF file. Convert a HTML file into a PDF file, or convert ANY file format to PDF file!
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 03-28-2008, 11:22 PM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: PDF Creating in PHP

Hi Kamal,
can we create PDF file without doing the above installation?
or is it needed to install in my server to use PDF function in my scripts?
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 03-29-2008, 01:39 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

Hi Jey,

Yes possible. when we use FPDF library than no need to installation process in our server.

Here i explain about FPDF...

FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 03-29-2008, 01:41 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

Advantages: high level functions. Here is a list of its main features:

* Choice of measure unit, page format and margins
* Page header and footer management
* Automatic page break
* Automatic line break and text justification
* Image support (JPEG and PNG)
* Colors
* Links
* TrueType, Type1 and encoding support
* Page compression

FPDF requires no extension (except zlib to activate compression) and works with PHP4 and PHP5.
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 03-29-2008, 01:43 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

What languages can I use?

The class can produce documents in many languages other than the Western European ones: Central European, Cyrillic, Greek, Baltic and Thai, provided you own TrueType or Type1 fonts with the desired character set. Chinese, Japanese and Korean are supported too.
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 03-29-2008, 01:44 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

What about performance?

Of course, the generation speed of the document is less than with PDFlib. However, the performance penalty keeps very reasonable and suits in most cases, unless your documents are particularly complex or heavy.
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 03-29-2008, 01:54 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

Here, we are going to see on converting HTML 2 PDF using PHP. we would be seeing how to use some free open source PHP scripts to accomplish this file conversion.

FPDF: The PDF Generator

The first and the main base for this file conversion is FPDF library. FPDF is a pure PHP class to generate PDF files on the fly. Let us start the PDF generation with a simple Hello world display.

PHP Code:
<?php
require('fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 03-29-2008, 01:56 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

To generate a pdf file, first we need to include library file fpdf.php. Then we need to create an FPDF object using the default constructor FPDF(). This constructor can be passed three values namely page orientation (portrait or landscape), measure unit, and page size (A4, A5, etc.,). By default pages are in A4 portrait and the measure unit is millimeter. It could have been specified explicitly with:

PHP Code:
$pdf=new FPDF('P','mm','A4'); 
It is possible to use landscape (L), other page formats (such as Letter and Legal) and measure units (pt, cm, in).

Then we have added a page to our pdf document with AddPage(). The origin is at the upper-left corner and the current position is by default placed at 1 cm from the borders; the margins can be changed with the function SetMargins().

To print a text, we need to first select a font with SetFont(). Let us select Arial bold 16:

PHP Code:
$pdf->SetFont('Arial','B',16); 
We use Cell() function to output a text. A cell is a rectangular area, possibly framed, which contains some text. It is output at the current position. We specify its dimensions, its text (centered or aligned), if borders should be drawn, and where the current position moves after it (to the right, below or to the beginning of the next line). To add a frame, we would do this:

PHP Code:
$pdf->Cell(40,10,'Hello World !',1); 
Finally, the document is closed and sent to the browser with Output(). We could have saved it in a file by passing the desired file name.

There are lot more functions in FPDF.

Need more info click here.
__________________
Thanks & Regards,
R.Kamalakannan.

Last edited by Kamalakannan : 03-29-2008 at 02:04 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 03-29-2008, 02:06 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

HTML2FPDF: The Converter

HTML2FPDF is a PHP Class library that uses the FPDF class library to convert HTML files to PDF files. This library consist of three classes namely PDF, HTML2FPDF and FPDF (modified FPDF class). The class PDF extends the class HTML2FPDF that extends the class FPDF.

Now let us see, how to convert a sample html page into a PDF file using HTML2FPDF Library. The html page contains a table that lists a few nations with their corresponding national flags. Below is the code for the conversion.

PHP Code:
<?
require('html2fpdf.php');
$pdf=new HTML2FPDF();
$pdf->AddPage();
$fp fopen("sample.html","r");
$strContent fread($fpfilesize("sample.html"));
fclose($fp);
$pdf->WriteHTML($strContent);
$pdf->Output("sample.pdf");
echo 
"PDF file is generated successfully!";
?>
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20 (permalink)  
Old 03-29-2008, 02:12 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: PDF Creating in PHP

First, we need to include the html2fpdf.php file that contains the HTML2FPDF class and an object is created using the constructor HTML2FPDF(). Then a new page is added to the pdf document using the function AddPage(). The html contents are read from the sample.html file using file functions. Then the html contents are written in to the pdf format using WriteHTML() function. The above sample code with the sample html file and images and the html2fpdf class libraries can be downloaded here.

The HTML2FPDF class library will be working best with the XHTML 1.0. Also the class does not support all the features available with HTML. To know the supported HTML tags and other features, Please refer HTML 2 (F)PDF Project.
__________________
Thanks & Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Games aicram Game Development 5 11-05-2008 08:41 PM
Creating password chocoguy Perl 0 01-01-2008 12:53 AM
Creating Cookies pranky HTML, CSS and Javascript Coding Techniques 2 11-21-2007 05:02 AM
How to creating an Alaram using j2me?? mobilegeek J2ME 0 07-16-2007 12:36 AM
creating components nssukumar Flash Actionscript Programming 4 05-22-2007 11:18 PM


All times are GMT -7. The time now is 02:53 PM.