2008年11月22日星期六

Re: [fw-formats] Zend_Pdf : How to calculate size of text ?

Hello everybody,

Maybe you want to solve this with Zend_Pdf,
but if you need to solve this as soon as possible, I have a tip for you:

I've been working on a task which should parse an HTML file to PDF,
and I found a php class that is the best I've ever saw:

It extends FPDF (fpdf.org - a great php class)

Different from others, this class doesn't require a lot of memory from your server.
Actually, we are using less than 32MB* for 200+ pages and almost 500 images (most are small images, but... you never know).
*Just remind to split your HTML into as many parts as possible (parse HTML is not that easy nor fast)

If using Zend_Pdf is not essential for you, I would strongly recommend using mPDF.

Anyway, I am just sharing a great pdfclass with you all.

Best regards,
Matheus Martins

2008/11/4 SŽébastien Cramatte <scramatte@zensoluciones.com>
Hello,

I need to use Zend_Pdf to make an invoice.
How I can calulate width of  a "text" with a specific font and size  ?

I've tried the method behind (http://devzone.zend.com/article/2525-Zend_Pdf-tutorial)
I've extend Zend_Pdf class and append the method ...

I've tried to call the method as this :

$this->widthForStringUsingFontSize($cell, Zend_Pdf_Font::FONT_HELVETICA, 8);


It works but seems that returns incorrect value because when I draw a vertical line to this same position, text and line are aligned !


public function widthForStringUsingFontSize($string, $font, $fontSize)
  {
      $drawingString = iconv('UTF-8', 'UTF-16BE//IGNORE', $string);
      $characters = array();
      for ($i = 0; $i < strlen($drawingString); $i++) {
          $characters[] = (ord($drawingString[$i++]) << 8) | ord($drawingString[$i]);
      }
      $glyphs = $font->glyphNumbersForCharacters($characters);
      $widths = $font->widthsForGlyphs($glyphs);
      $stringWidth = (array_sum($widths) / $font->getUnitsPerEm()) * $fontSize;             return $stringWidth;

  }


I've got the same problem when I try to right align data. As returned with is incorrect I'm not be abble to align my cells !

Any ideas ?

Regards


没有评论: