TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-29-2007, 01:19 PM   #1 (permalink)
The Acquainted
 
Join Date: Sep 2007
Posts: 126
Thanks: 4
Sam Granger is on a distinguished road
Default PDF Creation - Help!

I am using the following PHP PDF class: http://www.ros.co.nz/pdf/

However, I am having the following problem: I can't have a long paragraph without the text just continueing on the same line off the page.

This is my code:

PHP Code:
$pdf = new Cpdf();
$pdf->selectFont('/fonts/Times-Roman.afm');
$pdf->addText(10,770,15,$title);
$pdf->addText(10,740,10,'VEry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text');
$pdf->addText(10,30,10,'Site Name');
$pdf->stream(); 
The long text just contines on one line and it should start on a new line when the previous line is full.

Looking forward to help and suggestions!
Sam Granger is offline  
Reply With Quote
Old 10-29-2007, 01:30 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

If you use the Ezpdf class, there is a method called ezText which will take care of wrapping long strings (over multiple pages if needs be). All the relevant information can be found in the readme.pdf document included in the download on the site that you linked to.

Last edited by Salathe : 10-29-2007 at 03:02 PM.
Salathe is offline  
Reply With Quote
Old 10-29-2007, 03:14 PM   #3 (permalink)
The Acquainted
 
Join Date: Sep 2007
Posts: 126
Thanks: 4
Sam Granger is on a distinguished road
Default

I have tried that before... :(

PHP Code:
$pdf =& new Cezpdf('a4','P');
$pdf->ezSetCmMargins(2,2,2,2);
$pdf->selectFont('./fonts/Helvetica.afm');
$pdf->ezText('VEry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text!',10);
$pdf->ezStream(); 
Still stayed on one line!!
Sam Granger is offline  
Reply With Quote
Old 10-29-2007, 04:16 PM   #4 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

I am not sure how either of these programs work but you could always add the line breaks in yourself with a wordwrap?

Like:
$newtext = wordwrap($text, 8, "\n");

Where 8 is the limit per line and \n is your delimiter.

PHP Code:
$pdf =& new Cezpdf('a4','P');
$pdf->ezSetCmMargins(2,2,2,2);
$pdf->selectFont('./fonts/Helvetica.afm');
$szText ''VEry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text vry lannngge text!";
$pdf->ezText( wordwrap($szText, 20, "\n") );
$pdf->ezStream(); 
It does depend how the class works though, but wordwrap will simply limit it to 20 chars and then add a \n and carry on with the rest of the text...
__________________
Halo 3 Cheats
bluesaga is offline  
Reply With Quote
Old 10-29-2007, 10:42 PM   #5 (permalink)
The Acquainted
 
Join Date: Sep 2007
Posts: 126
Thanks: 4
Sam Granger is on a distinguished road
Default

Well, that works a bit - however, the following text is on the same line so you have multiple layers ontop of each other. :(
Sam Granger is offline  
Reply With Quote
Old 10-30-2007, 01:03 AM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Cezpdf seems to wrap the text just fine for me. I just tried it with a block of 'lorem ipsum' text which wraps nicely, even over multiple pages if there's enough text. See the attachments for my code, the sample text isn't as big as I'd hoped for (insanely small file size limits for attachments) but it gets the idea across.

Attached Files
File Type: php lipsumpdf.php (606 Bytes, 231 views)
File Type: txt lipsum.txt (4.4 KB, 207 views)
Salathe is offline  
Reply With Quote
Old 10-30-2007, 08:25 AM   #7 (permalink)
The Acquainted
 
Join Date: Sep 2007
Posts: 126
Thanks: 4
Sam Granger is on a distinguished road
Default

Damn, I tried your example too Salathe and still the same. Must be my host! :(

http://www.imgloader.com/uploads/lipsum.jpg
Sam Granger is offline  
Reply With Quote
Old 10-31-2007, 11:32 AM   #8 (permalink)
The Acquainted
 
Join Date: Sep 2007
Posts: 126
Thanks: 4
Sam Granger is on a distinguished road
Default

Looks like something went wrong when I was uploading the fonts, problem solved.Thanks guys!
Sam Granger is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

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


All times are GMT. The time now is 04:42 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design