Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's a way to calculate widths exactly, rather than using <a href="https://stackoverflow.com/questions/1283555/zendpdf-calculating-length-of-text-string-in-current-font-for-line-wrapping/1283586#1283586">Gorilla3D's worst case algorithm</a>.</p> <p>Try this code from <a href="http://devzone.zend.com/article/2525-Zend_Pdf-tutorial#comments-2535" rel="nofollow noreferrer">http://devzone.zend.com/article/2525-Zend_Pdf-tutorial#comments-2535</a></p> <p>I've used it in my application to calculate offsets for right-aligned text and it works</p> <pre><code>/** * Returns the total width in points of the string using the specified font and * size. * * This is not the most efficient way to perform this calculation. I'm * concentrating optimization efforts on the upcoming layout manager class. * Similar calculations exist inside the layout manager class, but widths are * generally calculated only after determining line fragments. * * @link http://devzone.zend.com/article/2525-Zend_Pdf-tutorial#comments-2535 * @param string $string * @param Zend_Pdf_Resource_Font $font * @param float $fontSize Font size in points * @return float */ function widthForStringUsingFontSize($string, $font, $fontSize) { $drawingString = iconv('UTF-8', 'UTF-16BE//IGNORE', $string); $characters = array(); for ($i = 0; $i &lt; strlen($drawingString); $i++) { $characters[] = (ord($drawingString[$i++]) &lt;&lt; 8 ) | ord($drawingString[$i]); } $glyphs = $font-&gt;glyphNumbersForCharacters($characters); $widths = $font-&gt;widthsForGlyphs($glyphs); $stringWidth = (array_sum($widths) / $font-&gt;getUnitsPerEm()) * $fontSize; return $stringWidth; } </code></pre> <p>With regard to performance, I haven't used this intensively in a script but I can imagine it's slow. I'd suggest writing the PDFs to disk, if possible, so repeat views are very fast, and caching/hard coding data where possible.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload