Images: Relative and Absolute URLs

830 views
Skip to first unread message

Esteban Cairol

unread,
Jul 9, 2009, 4:25:38 PM7/9/09
to dompdf
Hi,

Im having some problems when including image tags that use relative
URLs. Seems that dompdf doesn't find the image. For example, if I use
<img src="/img/logo.jpg" />, I get a red X and the image is not
displayed.

If I want them to appear, I have to put an absolute URL, like this:
<img src="http://www.mydomain.com/img/logo.jpg" />

Im using the Cake framework, PHP5.

Does somebody has an idea of what could be causing the problem? Any
help will be appreciated.
Thanks for the lib, and your time!

Esteban.

psychoactive

unread,
Jul 10, 2009, 12:53:55 PM7/10/09
to dompdf
It works absolutely fine for me, perhaps you should take out the
leading slash..? no need for /blah/img.jpg

just put blah/img.jpg

i have no problem with this, so i would make sure your path is correct

BrianS

unread,
Jul 10, 2009, 11:08:32 PM7/10/09
to dompdf
On Jul 10, 12:53 pm, psychoactive <psychoact...@gmail.com> wrote:
> It works absolutely fine for me

Nice pun, that one ;)

> perhaps you should take out the leading slash..? no need for
> /blah/img.jpg
>
> just put blah/img.jpg

That's not necessarily true. The web page could be in a subdirectory
of the site. So the path used really depends on his site structure.

On Jul 9, 1:25 pm, Esteban Cairol <ecai...@gmail.com> wrote:
> Im having some problems when including image tags that use relative
> URLs. Seems that dompdf doesn't find the image. For example, if I use
> <img src="/img/logo.jpg" />, I get a red X and the image is not
> displayed.
>
> If I want them to appear, I have to put an absolute URL, like this:
> <img src="http://www.mydomain.com/img/logo.jpg" />
>
> Im using the Cake framework, PHP5.

The main thing to focus on is how you're using DOMPDF. When you load
an HTML document via the local file system (e.g. $dompdf-
>load_html_file('myfile.html')) DOMPDF will have no knowledge of that
file being part of a web server. In this instance DOMPDF will assume
all path references in the document are local file system references.
This means DOMPDF will look for /img/logo.jpg in that location on the
file system. What you really want is for DOMPDF to look in /local/
filesystem/path/to/web/files/img/logo.jpg.

You only have one option if you don't want to rewrite all your image
source attributes to use a full URI. Specifically, load your HTML
document via your web server: $dompdf->load_html_file('http://
www.mysite.com/myfile.html');

Hope that helps.
-b

psychoactive

unread,
Jul 10, 2009, 11:50:55 PM7/10/09
to dompdf
sorry guess i was in a bit over my head on that one, /me is a novice
haha

good to have people like you around Brian!
> document via your web server: $dompdf->load_html_file('http://www.mysite.com/myfile.html');
>
> Hope that helps.
> -b

BrianS

unread,
Jul 11, 2009, 8:40:15 AM7/11/09
to dompdf
On Jul 10, 11:50 pm, psychoactive <psychoact...@gmail.com> wrote:
> sorry guess i was in a bit over my head on that one, /me is a novice
> haha
>
> good to have people like you around Brian!

I'm always glad to be able to help someone out. You do pretty well,
psycho. As much as I like to help people it's great to have a vocal
community as well. No one person can answer every query ... and still
have a day job ;)
Reply all
Reply to author
Forward
0 new messages