jjw*_*ign 13 php pdf-generation tcpdf
我已经和TCPDF合作了几个月了; 断断续续地.它对我的大多数HTML模板都运行得相当好,但是我总是遇到将图像放入PDF的问题.图像通常放在身体中,而不是头部.我的位置是左上角的固定位置,或者是相对于文档底部的位置.在任何一种情况下,我都有问题.当HTML中的文本发生变化时,我必须重新定位图像.多列表可能会使事情变得更加困难.注意:"class pdf扩展了TCPDF".
$this->pdf->AddPage();
$this->pdf->writeHTML($pdf_html);
$cur_page = $this->pdf->getPage();
$x_pos = $this->pdf->GetX();
$y_pos = $this->pdf->GetY();
// Place image relative to end of HTML
$this->pdf->SetXY($x_pos, $y_pos - 54);
$this->pdf->Image('myimage.png');
Run Code Online (Sandbox Code Playgroud)
有没有人知道将图像放入从HTML生成的PDF中的简单方法.我想将HTML分成两部分,但我不确定它是否也能正常工作.
hen*_*nna 20
我正在使用html img标签,并且运行良好.
$toolcopy = ' my content <br>';
$toolcopy .= '<img src="/images/logo.jpg" width="50" height="50">';
$toolcopy .= '<br> other content';
$pdf->writeHTML($toolcopy, true, 0, true, 0);
Run Code Online (Sandbox Code Playgroud)
对不起,我知道你已经接受了答案.然而,它似乎并没有真正回答你的问题,关于是图像不是在网络级别.
你考虑过使用file_get_contents(); 并简单地渲染base_64字符串.这样您就可以使用任何级别的图像,而无需担心它是否可公开访问.
例如:
$imageLocation = '/var/www/html/image.png';
$ext = end(explode(".", $imageLocation);
$image = base64_encode(file_get_contents($imageLocation));
$pdf->writeHTML("<img src='data:image/$ext;base64,$image'>");
Run Code Online (Sandbox Code Playgroud)
或者,不依赖于HTML解析器.从经验中减慢了生成的PDF的渲染速度,可以使用以下内容:
$image = file_get_contents('/var/www/html/image.png');
$pdf->Image('@'.$image);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38570 次 |
| 最近记录: |