DOMPDF图像未显示在服务器上

问题描述 投票:0回答:1

我遇到了一个非常常见的错误,即该图像未显示在服务器上,在本地服务器上,该图像仍然可以正常显示,我实际上查看了很多答案并尝试了很多方法,但仍然没有不能用,请看一下我的代码。

require_once("./vendor/dompdf_new/autoload.inc.php");
use Dompdf\Dompdf; //v0.8.3

class Pdfgenerator {

public function generate($html, $filename='', $stream=TRUE, $paper = 'A4', $orientation = "portrait")
{

    $dompdf = new DOMPDF();
    $contxt = stream_context_create([
        'ssl' => [
            'verify_peer' => FALSE,
            'verify_peer_name' => FALSE,
            'allow_self_signed'=> TRUE
        ]
    ]);
    $dompdf->setHttpContext($contxt);
    $dompdf->loadHtml($html);
    $dompdf->set_option('isRemoteEnabled', true);
    $dompdf->set_option('isHtml5ParserEnabled', true);
    $dompdf->set_option('debugKeepTemp', TRUE);
    $dompdf->setPaper($paper, $orientation);
    $dompdf->render();
    if ($stream) {
        $dompdf->stream($filename.".pdf", array("Attachment" => 0));
    } else {
        return $dompdf->output();
    }
}
}

// Using other file =========================================================
public function index()
{
    // $this->load->library('pdfgenerator');
    // $path = 'https://xxxxx.xx/images/logo.png';
    // $type = pathinfo($path, PATHINFO_EXTENSION);
    // $data = file_get_contents($path);
    // $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
    // $html = '<img src = "'.$base64.'" /><p>text</p>';
    // $this->pdfgenerator->generate($html,'filename');

    $html = '<img src ="'.$_SERVER['DOCUMENT_ROOT'].'/images/logo.png" /><p>text</p>';
    $this->pdfgenerator->generate($html,'filename');

}
php dompdf
1个回答
0
投票

[尝试将图像的路径更改为相对的路径,例如“ /images/logo.png”或“ ../images/logo.png”,看看是否适合您。

© www.soinside.com 2019 - 2024. All rights reserved.