TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   PDF Creation - Help! (http://www.talkphp.com/general/1358-pdf-creation-help.html)

Sam Granger 10-29-2007 01:19 PM

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!

Salathe 10-29-2007 01:30 PM

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.

Sam Granger 10-29-2007 03:14 PM

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!!

bluesaga 10-29-2007 04:16 PM

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...

Sam Granger 10-29-2007 10:42 PM

Well, that works a bit - however, the following text is on the same line so you have multiple layers ontop of each other. :(

Salathe 10-30-2007 01:03 AM

2 Attachment(s)
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.


Sam Granger 10-30-2007 08:25 AM

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

http://www.imgloader.com/uploads/lipsum.jpg

Sam Granger 10-31-2007 11:32 AM

Looks like something went wrong when I was uploading the fonts, problem solved.Thanks guys!


All times are GMT. The time now is 06:14 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0