我正在使用 mPDF 在我的网站上生成 PDF。 在我的 CSS 中,我使用图像作为背景:
.page{
height:297mm;
width:210mm;
background:url(../bookletFiles/exam_header.png) no-repeat scroll;
padding:400px 1.6cm 1.7cm 1.6cm;
}
这已经工作了很长时间。但最近我注意到,当我将 $mPDF->debug 声明为 true 时,我收到以下错误:
<B>mPDF error: </B>IMAGE Error (http://topografieindeklas.nl/wp-content/themes/topografieindeklas/bookletFiles/exam_header.png): Could not find image file
Strangley,当我删除 CSS 声明并在标签中使用完全相同的图像时,它会显示出来。 我已经尝试重新生成 .png 文件,将其替换为 .jpg 文件,但这没有任何结果。
我能想到的最近发生变化的唯一一件事是从 PHP 5.3 升级到 5.4,不过 allow_url_fopen 设置设置为 true。
有没有人想过为什么这张图片无法通过 CSS 加载以及如何解决?
最佳答案
在您的 pdf 文件视图中试试这个。
<?php $dir= $this->webroot."img/cake.icon.png"; ?>
<?php echo $dir; ?>
<img src="<?php echo $dir; ?>">
关于php - mPDF:CSS 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25844991/