/** * Overloaded GetStringWidth for calculating a String width with another Font/size than the current one */ function GetStringWidth($s, $psFontFamily = '', $psSize = '') { if ($psFontFamily == '' or $psSize == '' or !array_key_exists($psFontFamily, $this->fonts)) { return parent::GetStringWidth($s); } //Get width of a string in the current font $s = (string) $s; $cw = $this->fonts[$psFontFamily]['cw']; $w = 0; $l = strlen($s); for ($i = 0; $i < $l; $i++) { $w += $cw[$s[$i]]; } return $w * $psSize / 1000; }
<?php ini_set('memory_limit', '100M'); ini_set('max_execution_time', 0); require 'memory_opt.php'; $pdf = new PDF_Opt(); $pdf->AddPage(); $pdf->SetFont('Arial', '', 9); // generate a constant amount of text for testing $txt = ''; for ($i = 1; $i < 200; $i++) { $txt .= 'ashfsd kjsahkasjh akjhdsfjkh djshf sjkh '; } for ($i = 1; $i < 1000; $i++) { $pdf->Write(9, $txt); } $pdf->Output();