起初我认为TCPDF的GetStringWidth()无法正常工作,给我错误的宽度:
[---------------------------------------------- -------------------------------------------------- ----------------------]
我有一些文字,比如$ txt =“hallo”。
我试图通过内置函数GetStringWidth()获取字符串宽度 然后创建一个字符串宽度的单元格。
// 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');
?>
然而,创建的单元格是为了缩短它的内容。 如果我用快递尝试同样的方法,那就可以了。
我认为这是衡量GetStringWidth不能正确处理字体宽度的一个指标,因为Courier对每个字符的宽度都相同,这是有效的。
如何使GetStringWidth()正常工作
[---------------------------------------------- -------------------------------------------------- ----------------------]
今天我尝试用Firefox / Evince而不是chrome
打开它结果如下:
Firefox位于左侧,右侧是chrome。
生成的PDF文件是v.7.7
使用的chrome版本:
google-chrome-beta(41.0.2272.53-1)
这里可能出了什么问题?这真的是错吗?或者我在这里错过了一些东西?
由于
答案 0 :(得分:0)
你必须尝试替换:
NSURLSession
与
$pdf->Output("{$filename}.pdf", 'I');