ZF-1254: Improve Zend_Pdf Text-Functions

Issue Type: New Feature Created: 2007-04-12T04:21:50.000+0000 Last Updated: 2012-11-20T21:37:58.000+0000 Status: Open Fix version(s): Reporter: Niko Sams (nikosams) Assignee: None Tags: - Zend_Pdf

Related issues: - ZF-7145

Attachments: - Cell.php


Zend_Pdf currently only has a function drawText to draw Text at a specific position. For real-world usage it is every hard to work with this - as you have to calculate width and height of texts all the time (only possible ZF-313).

It would be nice to have Features like FPDF where you don't have to manually calculate everytime the y-position of the next line: - Write: - GetX/GetY: - SetX/SetY:

Another helpful FPDF-feature is helpfull wenn creating tables: - Cell: - MultiCell:

Additionally there exists a FPDF-Addon which allows to switch the font in a line - without having to calculate x and y positions: - Flowing Block:

Zend_Pdf has has many features fpdf lacks, it would be very nice if we could use Zend_Pdf - a much better OO-Interface, fpdf is one big class - utf8-support - use ttf-fonts directly

thanks, niko


Posted by Bill Karwin (bkarwin) on 2007-04-12T16:06:20.000+0000

Assign to Alexander.

Posted by Alexander Veremyev (alexander) on 2007-05-25T02:48:51.000+0000

Depends on document representation model, which should be designed before.

Postponed to post-1.0 period

Posted by Logan Buesching (ljbuesch) on 2007-09-25T12:09:49.000+0000

I have recently created a class that emulates the FPDF cells. Currently, it is very basic but allows for creating of a cell, positioning the cell, and aligning text inside of the cell. I have attached a diff that creates the functionality. A small example is the following:

<pre class="highlight">
//create and attach the cell to the first page, and center in the X and Y direction
$cell=new Zend_Pdf_Cell($pdf->pages[0],Zend_Pdf_Cell::POSITION_CENTER_X | Zend_Pdf_Cell::POSITION_CENTER_Y);
//align the text in the center
$cell->addText("The quick brown fox jumped over the lazy dog.",Zend_Pdf_Cell::ALIGN_CENTER);
//write the cell to the PDF document

Posted by Logan Buesching (ljbuesch) on 2007-09-25T12:10:22.000+0000

Patch for a cell class that allows simple cell creation and text alignment.

Posted by Logan Buesching (ljbuesch) on 2007-11-29T17:24:31.000+0000

I have updated the Cell.php file and fixed a few things. Added borders and word wrapping.

Posted by Logan Buesching (ljbuesch) on 2008-03-19T21:50:20.000+0000

I have just finished up a proposal using the Zend_Pdf_Cell, any comments are welcome. The proposal may be viewed at at…

Posted by Wil Sinclair (wil) on 2008-03-25T22:06:45.000+0000

Resetting 'fix version priority' and 'fix version' to be re-evaluated for next release.

Posted by Willie Alberty (willie) on 2008-12-04T22:34:57.000+0000

Unassigning Zend_Pdf issues currently assigned to me pending decision on ZF 2.0 release timeframe and potential contribution of comprehensive changeset.

Posted by Wil Sinclair (wil) on 2008-12-08T17:00:48.000+0000

Alex, please take a look at this and resolve as necessary.

Posted by Philip Iezzi (iezzip) on 2009-08-01T02:39:21.000+0000

in _wordWrap() I've encountered endless loops resulting in a 500 server error in the following case: A word of 1 character length (e.g. "-") would be the last word in a cell. This one character would still fit the cell width but we are trying to addText() the word plus a space separator (" "), after having calculated the word's width based on the 1-character word. We end up getting stuck in the while-loop.

I can't explain it any smarter as I'm having trouble with this complex recursion. But I got a quick and dirty fix for this:

<pre class="highlight">
<           $maxTextSection=$this->_makeTextSection(array_shift($splitSection));
>           $maxTextSection=$this->_makeTextSection(array_shift($splitSection) . ' ');
<               $this->addText($maxTextSection['text'].' ');
>               $this->addText($maxTextSection['text']);
<               $maxTextSection=$this->_makeTextSection(array_shift($splitSection));
>               $maxTextSection=$this->_makeTextSection(array_shift($splitSection) . ' ');
<           $this->addText($maxTextSection['text'].' '.$restOfText);
>           $this->addText($maxTextSection['text'].$restOfText);

I have updated the attached Cell.php

Posted by Philip Iezzi (iezzip) on 2009-08-05T00:04:21.000+0000

besides, there was another bug I've fixed long time ago:

<pre class="highlight">
--- ZF-1254_Cell.php    2009-08-01 11:26:04.000000000 +0200
+++ Cell.php    2009-08-05 09:01:13.000000000 +0200
@@ -601,7 +601,7 @@
        for ($x=0;$xcmap->glyphNumbersForCharacters($charArray);
+       $charArray=$textSection['font']->glyphNumbersForCharacters($charArray);
        //get the lengths

I've updated the attached Cell.php

Posted by Gerrit Kamp (gkamp) on 2010-01-07T14:40:41.000+0000

I really like the Zend PDF functionality. It's fast and stable. But I think many users would benefit from two key features: -Allow to parse HTML text (like here: -Allow to create tables (like above).

Are these types of functionality scheduled to be included in the core framework anytime soon? Without it, most PDF documents will look rather basic.

Posted by Peter Moolenaar (petermoolenaar) on 2010-01-22T03:48:57.000+0000

There is a proposal which has some very nice features related to this as well.…

Maybe an idea to implement that one?

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.