|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
That looks great. It has certainly given me a lot to think about.
Thanks loads toby |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Printing PDF files using PHP/MySQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|