SunQuest
 
           MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old November 6th, 2003, 11:29 AM
tobycatlin tobycatlin is offline
Hooner
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: norwich
Posts: 51 tobycatlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Post Printing PDF files using PHP/MySQL

Hey all

I have just started playing with PHP PDF function and have to admit that I am quite excited about it (not that excited)!

What i would like is to have a 'Print to PDF' button on each one of my web pages. Currently the webpage information is stored in a database table in HTML format.

It doesn't have to be an exact replica of the webpage a decent representation of content would be great.
So what i would like to be able to do is to strip the HTML out of the page and then put it back in to the PDF for people to save.

I have a HTML tag stripper which works great but when i try to write it to a PDF it come out in one long line.

I assume i need to break the string down and loop it so that it puts a new chunk of the string on a new line.

I was just thinking i can't be the first person to think of this and that someone else must have done it before me. If you are one of those people i would love to know how you did it, even if it is just some pointers.

thanks

toby

Reply With Quote
  #2  
Old November 6th, 2003, 11:54 AM
manoloweb manoloweb is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Monterrey MX
Posts: 49 manoloweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Well, I've heard of a C application to convert HTML to PDF, but what I have used is a PDF PHP generator, you need some extra coding to make a class to perform what you need, but it should be quite simple.

try this one: www.fpdf.org

Go to the tutorials section and take a look at the #5
__________________
The deal is not to know everything, but to know the email of the one who does.

Reply With Quote
  #3  
Old November 6th, 2003, 12:08 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
A quick and fairly easy way to handle this will be to use the PDF_string_width() function. Strip tags out of your text, split the text on spaces and put the words into an array. Determine your possible page width and start counting left to right in the array to build lines based on word widths and possible width. In pseudo-code:

Code:

//Assume $text is text from db with tags stripped.

$words=split(" ",$text);
foreach($words as $w){
    if(PDF_string_width($pdf,$w) + $current) > $possible_width){
        //Drop down a line
        //Print the word
        //Set $current to PDF_string_width($pdf,$w);
    }
    else{
        //Print the word
     }
}


You'll also probably want to stick another if inside that if statement that checks the row count and ends/begins the page if need be.

Reply With Quote
  #4  
Old November 11th, 2003, 11:30 AM
tobycatlin tobycatlin is offline
Hooner
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: norwich
Posts: 51 tobycatlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
That looks great. It has certainly given me a lot to think about.

Thanks loads

toby

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Printing PDF files using PHP/MySQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway