|
I've used fpdf a few times (some time ago) and last week took a look at Zend_Pdf
Let met start by saying i'm really happy with it, as it's so much clearer! However, i got disappointed quite quickly when it appeared that Zend_Pdf doesn't do text wrapping of large amounts of text. So, first i did a search with google to see if other people had tackled this issue. I found a class called Zend_Cell_Pdf, but unfortunately, that didn't work with my 1.5.2 installation. and every time i fixed one bug, i bumped into another. Also, i saw that even if i got it working it wouldn't support aligning the text with 'justify' - something i also need So, since it didn't seem to hard to program this functionality my self, i decided to do just that. One hour later, i had class that could create a text-block and even align it (left, right, center & justify). But then, the problems with Zend_Pdf started. I wrote a class that could do all the calculations and store the information about all the lines and spacing information. To keep things clean, i decided to overload the drawText function, by extending the Zend_Pdf_Page class and writing my own function. But since the $page object is created form the Zend_Pdf class i had to extend that class too, in order to let it instantiate my new page class. The problem is: both classes are filled with private variables that make extending them impossible. So, i'm left with two options: 1) modifying the Zend Framework classes so they can hadle my new functionality. I don't want this, because then i can never upgrade anymore 2) copying a lot code to my own classes to be able to write the output. this i obviously also don't want. I'm posting this here, to get some feedback. Maybe i'm overlooking some getter/setter functions? Maybe someone can explain to me if this was done intentionaly and why? i don't mind sharing my class btw. is that something i should post here on the mailinglist or is there a better place for that? |
|
Martijn
I encountered the same problem over a year ago and I managed to build my own paragraph and table functionality without extending any of the Zend classes. They work by accepting zend page object as an argument so the interface is a bit different then regular methods but they work fine. Karol
|
|
I would consider it a problem if you cannot extend the zend framework.
Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com Karol Grecki wrote: > Martijn > > I encountered the same problem over a year ago and I managed to build my own > paragraph and table functionality without extending any of the Zend classes. > They work by accepting zend page object as an argument so the interface is a > bit different then regular methods but they work fine. > > Karol > > > Martijn Korse wrote: > >> I've used fpdf a few times (some time ago) and last week took a look at >> Zend_Pdf >> Let met start by saying i'm really happy with it, as it's so much clearer! >> >> However, i got disappointed quite quickly when it appeared that Zend_Pdf >> doesn't do text wrapping of large amounts of text. So, first i did a >> search with google to see if other people had tackled this issue. I found >> a class called Zend_Cell_Pdf, but unfortunately, that didn't work with my >> 1.5.2 installation. and every time i fixed one bug, i bumped into another. >> Also, i saw that even if i got it working it wouldn't support aligning the >> text with 'justify' - something i also need >> >> So, since it didn't seem to hard to program this functionality my self, i >> decided to do just that. >> One hour later, i had class that could create a text-block and even align >> it (left, right, center & justify). But then, the problems with Zend_Pdf >> started. >> >> I wrote a class that could do all the calculations and store the >> information about all the lines and spacing information. >> To keep things clean, i decided to overload the drawText function, by >> extending the Zend_Pdf_Page class and writing my own function. >> But since the $page object is created form the Zend_Pdf class i had to >> extend that class too, in order to let it instantiate my new page class. >> The problem is: both classes are filled with private variables that make >> extending them impossible. So, i'm left with two options: >> 1) modifying the Zend Framework classes so they can hadle my new >> functionality. I don't want this, because then i can never upgrade anymore >> 2) copying a lot code to my own classes to be able to write the output. >> this i obviously also don't want. >> >> I'm posting this here, to get some feedback. Maybe i'm overlooking some >> getter/setter functions? Maybe someone can explain to me if this was done >> intentionaly and why? >> >> i don't mind sharing my class btw. is that something i should post here on >> the mailinglist or is there a better place for that? >> >> > > |
|
In reply to this post by Martijn Korse
Martijn,
Be sure to file issues for the enhancements you'd like to add, along with any code that could speed them along. Also, I'd file it as a bug that you can't extend these classes. In my opinion no property should ever be marked private in Zend Framework except in very specific cases (Zend_View, for example). -Matt On Sun, Jul 20, 2008 at 7:52 AM, Martijn Korse <[hidden email]> wrote:
|
|
In reply to this post by Micah Gersten
I agree, but if he needs to work with existing code it's better to go around it, instead of hacking ZF classes. Then he can safely upgrade to a newer version that will hopefully contain features he is after. I managed to do that without any hacks or code duplication and I can easily replace it with better implementation once those feature are added to Zend_Pdf. This is just my suggestion.
Karol
|
|
In reply to this post by Karol Grecki
That was my first approach (passing the $page object to my own class), so i could then use $page->drawText(). The problem is that drawText() doesn't allow for modification of the 'header'; i don't know the official PDF word for that, but what i mean is the BT\n it adds to content just before outputting the actual contents of the string. This would be fine if it wasn't for my align=justify, which needs a different header. That's why i decided to write my own Zend_Page class and overload the drawText() method so i could give an extra argument to modify these headers. But doing so gave the before mentioned problems with all those private variables. Karol, can i ask how you solved this problem? btw, thank you all for your feedback so far. I will file a bug report later today |
I never implemented "justify", left/right was all I needed. So perhaps I never encountered this particular problem. Karol |
|
In reply to this post by Martijn Korse
For those who interested, i issued this as a bug:
http://framework.zend.com/issues/browse/ZF-3701 As soon as i've created a (working) example of my class on my private website, i'll use that to file a suggestion too. |
|
In reply to this post by Martijn Korse
On Jul 20, 2008, at 7:52 AM, Martijn Korse wrote:
> I wrote a class that could do all the calculations and store the > information > about all the lines and spacing information. > To keep things clean, i decided to overload the drawText function, by > extending the Zend_Pdf_Page class and writing my own function. > But since the $page object is created form the Zend_Pdf class i had to > extend that class too, in order to let it instantiate my new page > class. > The problem is: both classes are filled with private variables that > make > extending them impossible. So, i'm left with two options: > 1) modifying the Zend Framework classes so they can hadle my new > functionality. I don't want this, because then i can never upgrade > anymore > 2) copying a lot code to my own classes to be able to write the > output. this > i obviously also don't want. > > I'm posting this here, to get some feedback. Maybe i'm overlooking > some > getter/setter functions? The Zend_Pdf_Page::rawWrite() method was intended to allow you to write your own data to the page's content stream so subclassing wouldn't strictly be necessary. Unfortunately, it had an empty implementation. I've written an implementation for that method and committed it to the framework trunk: http://framework.zend.com/issues/browse/ZF-3704 This should eliminate your need to subclass Zend_Pdf and Zend_Pdf_Page at all. Instead, move your code to a helper layout class which can call rawWrite() on the appropriate page object. > Maybe someone can explain to me if this was done intentionaly and why? Zend_Pdf is one of the oldest framework components. Most of the core classes haven't changed much since the initial implementations over two years ago. I believe this was probably just a mistaken choice between 'private' and 'protected' when the classes were first written. I see you've created ZF-3701 to address the visibility declarations, which I endorse. I should mention that Kevin McArthur and I have been collaborating on a comprehensive update to Zend_Pdf for the last several months. One of the most significant pieces of the project is a true text layout engine, which handles calculation of line breaks, text alignment, and more. This message describes the enhancements: http://www.nabble.com/Upcoming-Zend_Pdf-Enhancements-td16509067.html The project has grown a bit since sending that original message, resulting in a complete rewrite of Zend_Pdf's core, which has taken much longer than expected. Fortunately, the core rewrite was finished last week and we are in the midst of final testing for the commercial project that spurred the development. I would estimate that we're about two weeks away from being ready to post our reference implementation along with the proposals for what would become Zend_Pdf 2.0. I will be posting additional details to the fw-formats list when we're ready to release the code into the wild. -- Willie Alberty Spenlen Media [hidden email] http://spenlen.com/ |
|
In reply to this post by Martijn Korse
Here's my code, for those who are interested: http://devshed.excudo.net/scripts/php/source/excudo+pdf+textblock |
|
In reply to this post by Willie Alberty
I would say it has grown to impressive proportions ![]() It all sounds very good! I'll have detailed look later and will sure give feedback if i have any. |
| Powered by Nabble | Edit this page |
