背景图像不显示在 dompdf 中
由于某种原因,无论我如何尝试,背景图像都不会显示在 dompdf 中。我也把直接网址贴出来了。他们都没有工作。有 dompdf 经验的人可以告诉我我需要做什么吗?
值得注意的是,其他图像看起来也很好。只有背景图像才会引起问题。这是背景图像之一:
body{
font-size:15px;
background:url(bg.jpg) repeat-x bottom left;
}
For some reason, the background image doesn't show in dompdf no matter what I try. I've put the direct url as well. None of them worked. Can someone with dompdf experience tell me what I need to do?
It's important to note that other images appear just fine. It's only the bakground images that are causing issues. Here is one of the background images:
body{
font-size:15px;
background:url(bg.jpg) repeat-x bottom left;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用 DOMODF 0.5.1?它可能在解析背景速记时遇到问题。您可以尝试将通用背景属性分解为特定属性:
我还发现有时我必须提供完整的 URL ( http://example.com/bg.jpg)。
在该版本的 DOMPDF 中,该属性的处理存在一些问题。您可以考虑升级到 0.6.0 代码库(目前为 beta 1)。与之前的版本相比,它有许多改进。
Using DOMODF 0.5.1? It's probably having trouble parsing the background shorthand. You could try breaking up the generic background property into the specific properties:
I also found that sometimes I had to supply a full URL (http://example.com/bg.jpg).
The handling of this property is a little buggy in that version of DOMPDF. You might consider upgrading to the 0.6.0 code base (currently at beta 1). It has a number of improvements over the previous release.
嗯,我遇到了同样的问题,在我的本地 XAMMP(Windows)中它可以正常工作,但是当移动到实时服务器时背景图像没有显示。
寻找解决方案无果后,终于解决了。
这不起作用:
这就像一个魅力:
我希望这能有所帮助。
Well, I had the same issue, in my local XAMMP (windows) it worked as it should, but when moving to a live server background images didn't show up.
After looking for a solution without success, finally solved it.
This wasn't working:
This worked like a charm:
I hope this can help.
它看起来像 DOMPDF 支持背景图像,所以我必须假设文件路径是错误的。
如果添加
是否有效?
我发现在我使用 DOMPDF 的上一个项目中,我需要将图像文件指向文件系统上的它(而不是 webroot 的相对路径),并且我必须使用最终看起来像这样的根
路径DOCROOT 变为
/user/me/public_html/
。为了在发送到 DOMPDF 之前将其作为纯 HTML 进行测试,我执行了str_replace()
将DOCROOT
更改为/
(相对于我的路径)。It looks like DOMPDF supports background images, so I have to assume that the filepath is wrong.
If you add
<img src="bg.jpg" alt="" />
does it work?I've found in the last project I used DOMPDF I needed to point the image file to it on the filesystem (not a relative path to webroot), and I had to use a root path that ended up looking like this
Where
DOCROOT
became/users/me/public_html/
. To test it as plain HTML before I sent to DOMPDF, I did astr_replace()
to change theDOCROOT
to/
(relative to my path).由于某些奇怪的原因我遇到了同样的问题
dompdf ver 0.6.1
但样式标签中设置的背景图像不起作用
希望有帮助
for some odd reason I had the same problem
dompdf ver 0.6.1
but background-image set in the style tag didn't work
hope that helps
在您的配置文件中,将 DOMPDF_ENABLE_REMOTE 设置为 true。
然后在您的页面或样式表中,使用 src 标记中的完整路径(即“http://yoursite.com/images/imagename.png”)或样式表中的 url()。
In your config file, set
DOMPDF_ENABLE_REMOTE
to true.Then in your page or style sheet, use the full path (i.e., "http://yoursite.com/images/imagename.png") in the src tag or the url() in the style sheet.