Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 3.33 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-21-2008, 04:23 AM   PM User | #1
razaksamad
New Coder

 
Join Date: Jan 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
razaksamad is an unknown quantity at this point
convert web page to pdf

anybody can help me, how to convert from web page to pdf use a simple php scripts .........thanks
razaksamad is offline   Reply With Quote
Old 01-21-2008, 08:42 AM   PM User | #2
student101
Regular Coder

 
student101's Avatar
 
Join Date: Nov 2007
Posts: 610
Thanks: 80
Thanked 13 Times in 13 Posts
student101 is on a distinguished road
Easy stuff,
What do you need/want to convert to pdf?
student101 is offline   Reply With Quote
Old 01-21-2008, 09:08 AM   PM User | #3
razaksamad
New Coder

 
Join Date: Jan 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
razaksamad is an unknown quantity at this point
yuppp...i want to convert from html page to pdf page........hmmm...any ideas...
razaksamad is offline   Reply With Quote
Old 01-21-2008, 09:59 AM   PM User | #4
student101
Regular Coder

 
student101's Avatar
 
Join Date: Nov 2007
Posts: 610
Thanks: 80
Thanked 13 Times in 13 Posts
student101 is on a distinguished road
Thumbs up

Quote:
Originally Posted by razaksamad View Post
yuppp...i want to convert from html page to pdf page........hmmm...any ideas...
Here is a basic one.

You could've just googled your question and found these?

http://bg2.php.net/manual/en/ref.pdf.php
http://www.easysw.com/htmldoc/

Quote:
In order the code to work, the following line in your php.ini has to be uncommented:
extension=php_pdf.dll
PHP Code:
<?php require_once('Connections/cnTest.php'); ?>
<?php
// select data from database for the PDF
mysql_select_db($database_cnTest$cnTest);
$query_rsReportData "SELECT * FROM categories";
$rsReportData mysql_query($query_rsReportData$cnTest) or die(mysql_error());
$row_rsReportData mysql_fetch_assoc($rsReportData);
$totalRows_rsReportData mysql_num_rows($rsReportData);
?>
<?php
// create handle for new PDF document
$pdf pdf_new();
// open a file
pdf_open_file($pdf"");

// Set Info
pdf_set_info($pdf"Author""Your name");
pdf_set_info($pdf"Title""Report");
pdf_set_info($pdf"Creator""Your name");
pdf_set_info($pdf"Subject""Report");

// start a new page (A4)
pdf_begin_page($pdf595842);

// path of your TTF font directory 
$fontdir "C:\WINDOWS\Fonts";

// Open .TTFs (true type fonts)
pdf_set_parameter($pdf"FontOutline""ArialItalic=$fontdir\ariali.ttf");
pdf_set_parameter($pdf"FontOutline""ArialBold=$fontdir\ARIALBD.TTF");
pdf_set_parameter($pdf"FontOutline""Arial=$fontdir\ARIAL.TTF");

// ------ Start output of the PDF Content ------//
// set the font - Arial Bold 15
$font pdf_findfont($pdf"ArialBold""host",0); pdf_setfont($pdf$font15);  
// output document title
pdf_show_xy($pdf"Categories Report"50788);
// draw a line
pdf_moveto($pdf20780);
pdf_lineto($pdf575780);
pdf_stroke($pdf);

// set the font - Arial Italic 12
$font pdf_findfont($pdf"ArialItalic""host",0); pdf_setfont($pdf$font12);
$y 750;
// output data header
pdf_show_xy($pdf"Category:"50$y);
$y -= 5;

// set the font - Arial 10
$font pdf_findfont($pdf"Arial""host",0); pdf_setfont($pdf$font10);

// output the data from Database
do 
{       
$y -= 15;
        
pdf_show_xy($pdf$row_rsReportData['name'], 50$y);

while (
$row_rsReportData mysql_fetch_assoc($rsReportData));

// ------ End output of the PDF Content ------//

// end page
pdf_end_page($pdf);

// close and save file
pdf_close($pdf);

$buf pdf_get_buffer($pdf);
$len strlen($buf);

header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=report.pdf");
echo 
$buf;

pdf_delete($pdf);
?>
<?php
mysql_free_result
($rsReportData);
?>

Last edited by student101; 01-21-2008 at 10:03 AM..
student101 is offline   Reply With Quote
Old 01-21-2008, 01:02 PM   PM User | #5
M.W.S.
New Coder

 
Join Date: Jan 2008
Location: At home :p
Posts: 39
Thanks: 7
Thanked 1 Time in 1 Post
M.W.S. is an unknown quantity at this point
and if you don't have access to php.ini, you can use http://sourceforge.net/projects/html2fpdf libraries. You can easily convert html content of file into PDF
M.W.S. is offline   Reply With Quote
Old 01-22-2008, 12:09 AM   PM User | #6
razaksamad
New Coder

 
Join Date: Jan 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
razaksamad is an unknown quantity at this point
it works

thank you sooooooooooooo much
razaksamad is offline   Reply With Quote
Old 01-22-2008, 04:58 AM   PM User | #7
student101
Regular Coder

 
student101's Avatar
 
Join Date: Nov 2007
Posts: 610
Thanks: 80
Thanked 13 Times in 13 Posts
student101 is on a distinguished road
Sure thing~
student101 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:07 AM.


Advertisement
Log in to turn off these ads.