tags:

views:

200

answers:

2

For some reason, the background image doesn't show 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; }

A: 

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).

alex
direct img tags work fine. it's only the background images that don't work. the file path is correct because when I view the html, it works. when I take that same exact html and render it through dompdf, it doesn't work
Refiking
@Refiking That is what I was saying, I've had many times where I view the HTML and it is fine, but I need to change the path to the image once it needs to be rendered with DOMPDF to get it to work.
alex
If that's the case, then why can I see the other images just fine, but can't see the background image if they have the same path?
Refiking
@Refiking I'm sorry I don't know... DOMPDF can be a pain sometimes!
alex
A: 

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.

BrianS