背景图像不显示在 dompdf 中

发布于 2024-09-11 07:54:41 字数 234 浏览 4 评论 0原文

由于某种原因,无论我如何尝试,背景图像都不会显示在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

|煩躁 2024-09-18 07:54:41

使用 DOMODF 0.5.1?它可能在解析背景速记时遇到问题。您可以尝试将通用背景属性分解为特定属性:

background-image: url(bg.jpg);
background-repeat: repeat-x;
background-position: bottom left;

我还发现有时我必须提供完整的 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:

background-image: url(bg.jpg);
background-repeat: repeat-x;
background-position: bottom left;

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.

神经大条 2024-09-18 07:54:41

嗯,我遇到了同样的问题,在我的本地 XAMMP(Windows)中它可以正常工作,但是当移动到实时服务器时背景图像没有显示。

寻找解决方案无果后,终于解决了。

这不起作用:

body{ font-size:15px; background-image:url(<?php echo getcwd(); ?>/bg.jpg); background-repeat:repeat;}

这就像一个魅力:

body{ font-size:15px; background-image:url(./bg.jpg); background-repeat:repeat; }

我希望这能有所帮助。

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:

body{ font-size:15px; background-image:url(<?php echo getcwd(); ?>/bg.jpg); background-repeat:repeat;}

This worked like a charm:

body{ font-size:15px; background-image:url(./bg.jpg); background-repeat:repeat; }

I hope this can help.

纸短情长 2024-09-18 07:54:41

它看起来像 DOMPDF 支持背景图像,所以我必须假设文件路径是错误的。

如果添加 是否有效?

我发现在我使用 DOMPDF 的上一个项目中,我需要将图像文件指向文件系统上的它(而不是 webroot 的相对路径),并且我必须使用最终看起来像这样的根

<img src="<?php echo DOCROOT; ?>assets/images/bg.jpg" alt="" />

路径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

<img src="<?php echo DOCROOT; ?>assets/images/bg.jpg" alt="" />

Where DOCROOT became /users/me/public_html/. To test it as plain HTML before I sent to DOMPDF, I did a str_replace() to change the DOCROOT to / (relative to my path).

别再吹冷风 2024-09-18 07:54:41

由于某些奇怪的原因我遇到了同样的问题
dompdf ver 0.6.1

  1. 在 img 标签中需要完整的本地路径
  2. 作为背景图像相对路径仅起作用,
    但样式标签中设置的背景图像不起作用

希望有帮助

for some odd reason I had the same problem
dompdf ver 0.6.1

  1. in the img tags the full local path was needed
  2. as a background image the relative path worked only,
    but background-image set in the style tag didn't work

hope that helps

陪你搞怪i 2024-09-18 07:54:41

在您的配置文件中,将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文