DOMPDF不显示图像由PHP文件生成(dompdf not displaying image ge

2019-06-26 02:27发布

我使用DOMPDF生成PDF文件。 在该文件中,我包括上飞通过PHP使用而产生的图像;

<img src="image.php" />

当我查看网页,我可以看到一个错误说“未找到图像”可链接到当你点击它,显示精细的所谓未找到图像。

我已经尝试添加.png文件扩展名的网页生成图像,但是这并没有任何区别。 我还保存生成的图像到服务器,并链接到该代替,它工作正常。

我能想到的解决这个问题的唯一方法是在服务器上保存的图像,然后链接到。 理想情况下,我不想这样做,所以我想知道是否有人收到或如果任何人能想到它的修复遇到此。

我使用DOMPDF的版本是0.6.0 Beta 3中,我使用它与笨。

Answer 1:

你是如何加载HTML文档到DOMPDF? $dompdf->load_html() $dompdf->load_html_file() 要访问一个PHP生成的图像,你应该使用后者。 此外,除非你是通过Web服务器DOMPDF加载文档将抓住文件本身,而不是渲染的文件。 由于image.php是不是有效的图像类型DOMPDF将无法加载它。

有两个解决方案:

  1. 通过您的Web服务器,如将原稿$dompdf->load_html_file('http://example.com/mydoc.html'); 。 当你这样做的图像参考将被解释为http://example.com/image.php
  2. 参考使用一个完整的URL(包括域)的图像,使得服务器将其发送回DOMPDF,例如之前对其进行处理<img src="http://example.com/image.php" />


Answer 2:

首先添加此标记img src="image.php" ,你需要指定完整的根在那里位于你的形象,所以它最末端像JPG或PNG等所需的格式,并在配置文件中( dompdf_config.inc.php ),你需要改变这一行DOMPDF_ENABLE_REMOTE ,这对他的默认值是假的变化,以真实,这是所有:)



Answer 3:

您可以使用作为替代支持的Base64编码的图像数据

$html = '<div>
    <p>IMAGE</p>
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABMCAIAAACnG28HAAAABmJLR0QA/wD/AP%2BgvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1AgeBS42B7vBqgAAEhBJREFUeNrtnd%2BPHEcVhfcfBoknxAOIh0g88EsIIqKI1UprObYVe23FwQmskO0EYSskkCgkEo5MCMgoGBABhBDkIX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S7pQp1zuLN66%2BoAjqe1Gjzd6OUXBlKj8cnsXWtxx7uzETbHCIAZl6kMwCSOXo2g3asTJeqs36Z0TBZV55fHzbevfuz/ikEQ6ohRffef/%2BvfvUN37%2BNn%2B%2B994DD7wsLdgsB/xJB%2BoGvSxvXM7CsESk9/9vUjpHna9ovJatxCnXRlfn6WCvT3y06KS2MMTJ8WrnADJmRqt0WgWp/eajj5WmIuYnSyklN6qPlbhC8e7MEI1zd9oXAV7g9NfVn1jpCT9Jn%2Bkk1ciccSwfIm2FsmLic/DJ3/9JzQUcO941WYFf1c32LTWSXG%2B4QR/rwQcfRfKP//TJoz885jjIZuCZMpCEKLQwHMi%2BfVUuoBZgpRO0wgTQHE0MTyRTwj1UC7tIz2yEA8/U8lrTqNMglQkGHAqCT44Ljf/yHaXDBc5WLeu%2B%2B7bmtXVmeLZkLJPJ9F12/JWFyZrMI0wLF%2Ba13BR%2BJhdBCUFORlelTzVWftlbKHd/Xxjr3n0xvlD0T3zx8cPkbox/GHpry9iT51zM7dloEFHkTeGG1UNZeQ7Ct07sbG/zTpe8nOgMgroTsFYpeSWOby7Z8ZCvGbnZK5yAtdPAmqV9jk5N22LxscRkZpfHIauHhH0v5gSsXSlmUJ2L7Skjunn/Vt447MtRzKKegDWVVTzCkpJ1eDGvfjRb32f4NmTKJ2A9FcWnhvKWnrwrS4RtYh99AtZTUcqLSU8eAa/fpy17TYw1ldWtoW5W3ouc9yX3vZRlAtZUFhcfi8q/PMlrz/2/hxOwprKWNfTB2sTfh9%2BBPQFrKmOtoU/x5%2BVQG32qYgLW00Va/vcb/z3nRu81AevpKr5tYPi9EhOwprK7ZQLWVCZgTeX8lP8CuDenorrKqfIAAAAASUVORK5CYII%3D">
</div>':

require_once('dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF ();
$dompdf->load_html ($html);
$dompdf->render ();
$dompdf->stream ("Test.pdf", array ("Attachment" => false));

获得从以base64 PHP中的图像:

//getIMG.php?data=1&id=123
if ($data == 1) {
    echo "data:image/".$adj->type.";base64,"
            .str_replace ("\n", "", base64_encode ($adj->imageBinary));
}


文章来源: dompdf not displaying image generated by PHP file