我在 Codeigniter 3 项目中使用 dompdf 简单地使用以下方法打印 pdf 中的一些数据。这是我的控制器方法:
public function index() {
// Load Dompdf library
$dompdf = new Dompdf\Dompdf();
// HTML content with background image inline
$html = '
<html>
<head>
<style>
body {
background-image: base_url('uploads/background_images/CoverImage1.jpg');
}
</style>
</head>
<body>
<h2>Background Image</h2>
<p style="color:red">By default, the background image will repeat itself if it is smaller than the element where it is specified, in this case the body element.</p>
</body>
</html>
';
// Load HTML to Dompdf
$dompdf->loadHtml($html);
// Set base path for resolving relative URLs
$dompdf->setBasePath(realpath(FCPATH . 'uploads/background_images/'));
// Render PDF
$dompdf->render();
// Output PDF to browser
$dompdf->stream("hello_world.pdf", array("Attachment" => false));
}
已创建 pdf,但背景图像丢失。
我应该如何定义 dompdf 3.0.0 的背景图像。
谁能帮忙解决一下吗?
提前致谢。
你就快拥有了
尝试:
body {
background-image: url(base_url('uploads/background_images/CoverImage1.jpg'));
}
代替:
body {
background-image: base_url('uploads/background_images/CoverImage1.jpg');
}
祝你好运