TCPDF-图片仅显示一次 [英] TCPDF - image displayed only once

查看:118
本文介绍了TCPDF-图片仅显示一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用TCPDF版本6.0.010生成多页pdf. 当我使用版本5.9.009时,您在下面看到的脚本可以完美地工作.

I'm trying to generate a multiple page pdf with TCPDF version 6.0.010. The script you see below worked perfectly when I was using version 5.9.009.

每个页面上都有徽标. TCPDF版本6.0.010生成的pdf仅在该徽标上显示一次(在第1页上). 当我在这些页面上加载不同的图像时,这些图像会正确显示(只要没有重复).

Every page has a logo in it. The pdf generated by TCPDF version 6.0.010 shows only once (on 1st page) this logo. When I load different images on these pages, the images are displayed correctly(as long as there are no duplicates).

    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->setPrintHeader(false);
    $pdf->setPrintFooter(false);
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetMargins(PDF_MARGIN_LEFT, 10, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    $pdf->SetFont('freesans', '', 18);
    foreach ($items as $item) {
        $pdf->AddPage();
        $html = myHtmlTemplate($item);
        $pdf->writeHTML($html, true, false, true, false, '');   
    }

    $file = $pdf->Output('myPDF.file', 'S');

推荐答案

我有一个相同的问题,我的解决方法是将图像加载为base64图像字符串,然后改用它.

I have the same problem my work around is to load the image as a base64 image string and use that instead.

示例:

$img= "myimage.jpg";

$imgdata = 'data: '.mime_content_type($img).';base64,'. base64_encode(file_get_contents($img));

$html = "<img src=\"$imgdata\"/>";

这应该有所帮助,这不是一个解决方法,并且速度稍慢,但是对我有用. 我相信这会有所帮助.

This should help, its not a fix and it is a bit slower, but it works for me. I Trust this helps.

这篇关于TCPDF-图片仅显示一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆