[英]chrome not displaying pdf right?
At first i thought TCPDF's GetStringWidth() was not working right, giving me the wrong width: 起初我以为TCPDF的GetStringWidth()工作不正确,给了我错误的宽度:
[----------------------------------------------------------------------------------------------------------------------] [------------------------------------------------- -------------------------------------------------- -------------------]
I have some text like $txt = "hallo". 我有一些文本,例如$ 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. 我试图通过内置函数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');
?>
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. 我认为这是对GetStringWidth的一种不正确处理字体宽度的措施,这是因为Courier对于每个字符都具有相同的宽度,这是可行的。
How can I get GetStringWidth() working 我如何让GetStringWidth()工作
[----------------------------------------------------------------------------------------------------------------------] [------------------------------------------------- -------------------------------------------------- -------------------]
Today I tried opening it with Firefox/Evince instead of chrome 今天,我尝试使用Firefox / Evince而不是chrome打开它
Here's the result: 结果如下:
Firefox is on the left, chrome on the right.
Firefox在左侧,Chrome在右侧。
The generated PDF file is v. 1.7 生成的PDF文件为1.7版
Used version of chrome: 二手的chrome版本:
google-chrome-beta (41.0.2272.53-1) 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');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.