At first i thought TCPDF's GetStringWidth() was not working right, giving me the wrong width:
[----------------------------------------------------------------------------------------------------------------------]
I have some text like $txt = "hallo".
I've tried to get the strings width via the built in function GetStringWidth() and then create a cell with the strings width.
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setFontSubsetting(true);
$pdf->AddPage();
$pdf->SetFont('times', '', 20);
$pdf->SetCellPadding(0);
$txt = "hey i'm santa clause";
$width = $pdf->GetStringWidth($txt);
$pdf->Cell($width, $h=0, $txt, $border=1, $ln=0, $align='', $fill=false, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M');
$pdf->Output('example_001.pdf', 'I');
?>
The created cell however is to short for it's content. If I try the same with courier it works fine.
I think it's a measure of GetStringWidth not processing the font's width right, cause of Courier having the same width for each character, which works.
How can I get GetStringWidth() working
[----------------------------------------------------------------------------------------------------------------------]
Today I tried opening it with Firefox/Evince instead of chrome
Here's the result: Firefox is on the left, chrome on the right.
The generated PDF file is v. 1.7
Used version of chrome:
google-chrome-beta (41.0.2272.53-1)
What could have gone wrong here? Is it really chromes fault? Or am I missing somethign here?
Thanks
You must try with replacing:
$pdf->Output("{$filename}.pdf", 'I');
with
$pdf->Output("{$filename}.pdf", 'D');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.