Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background-image url absolute paths #1683

Closed
SergioReis97 opened this issue Mar 7, 2018 · 16 comments
Closed

Background-image url absolute paths #1683

SergioReis97 opened this issue Mar 7, 2018 · 16 comments
Labels
Milestone

Comments

@SergioReis97
Copy link

I've been reading the issues about images ( i know there's a couple already) but none fitted 100% what i need, #1209 is basicly the same but that solution doesn't work in my case since i need image on every page.

When trying to use background-image prop, images never load, but the exacly same path does load on a img tag,

Some of urls i tried.

<body style="background-image: url('/var/www/html/project/storage/app/randomFolder/sidebar.png');> 
<body style="background-image: url('/storage/app/randomFolder/sidebar.png');>
<body style="background-image: url('./storage/app/randomFolder/sidebar.png');>

However, this img tag works
<img src="/var/www/html/project/storage/app/randomFolder/sidebar.png">

If I place an image on public folder and try

<body style="background-image: url('http://localhost/sidebar.png');>

It does load, but i'm trying to not have the image publicly accessible.
Also a route to access the image brings kind of the same problem since the request to get the image would need to be authentified,

As a workaround i'm going to try to fetch the file instead of the path and attempt to use it as a base64 string url encoded since base64 image seem to work.

Sys info:

Linux mint 18.2,php 7.0, Laravel 5.5 using:
"barryvdh/laravel-dompdf": "^0.8.1",
The folders do have the right permissions

Issues for reference
#50, #1209, #1346

@jonathanpmartins
Copy link

Same problem here.

@SergioReis97
Copy link
Author

@jonathanpmartins As a work around I can confirm you that passing the image as base64 does indeed work.

@jonathanpmartins
Copy link

jonathanpmartins commented Nov 29, 2018

than you very much @SergioReis97! This solve my problem! Base64 it is...

@bsweeney
Copy link
Member

Does this continue to be an issue? I was unable to reproduce using the latest version.

@Julianoe
Copy link

Julianoe commented Mar 10, 2019

Yes it is an issue. I'm building for many months now a plugin working with domPDF among other things and i never never never managed to set a working background image. I'd love to help to improve the domPDF on this but how could I?

For now i just tried the current release 0.8.3 with php 7.2 and it does not work. I also tried the current nightly version and it did not work either. I tried with both relative and absolute paths.

I also tried with a base64 encoding function and then it worked. It also worked with a simple url, if isRemoteEnabled on true of course (which i can't use). Still can't use background with a path..

@bsweeney
Copy link
Member

OK, yes, I think I can confirm this is a problem ... at least with minimal testing. I'll do some more research and provide a fix if necessary for the next release.

@bsweeney bsweeney added bug and removed question labels Mar 10, 2019
@bsweeney bsweeney added this to the 0.8.4 milestone Mar 10, 2019
@pichotweb
Copy link

I've got the same problem here, base64 and external links works fine as long the system path dont. Using php 7.3 and dompdf 0.8.3. Any clue on how I can help to fix it?

@bsweeney bsweeney modified the milestones: 0.8.4, dompdf-next Jan 2, 2020
@halfpastfouram
Copy link

@bsweeney If you can tell me where to look I can probably make a PR for this to help out.

@bsweeney
Copy link
Member

This may not still be an issue with the 0.8.6 release. We made some changes to how local resources are processed. Is anyone able to confirm?

@halfpastfouram
Copy link

It is still an issue. I had to change code for this today. It's not only with background images, but also with an IMG tag.

@bsweeney
Copy link
Member

bsweeney commented Nov 10, 2020

For local resources, generally, the issue after an upgrade to 0.8.6 may be related to the change to honor the chroot (see #2229).

I'll double-check, but in working on the updates I know I tested URLs of the form indicated by the OP.

@bsweeney bsweeney modified the milestones: dompdf-next, 1.0.0 Nov 10, 2020
@bsweeney
Copy link
Member

I believe this should be addressed now. FIlesystem URLs beginning with a "/" are retrieved relative to the filesystem root (not the document root). There is an issue with not root relative references from external stylesheets that have a different base path from the document itself. That should be fixed by (5a9fafb).

Please post back if this is still problematic when using the forthcoming 1.0.0 release.

@bilogic
Copy link

bilogic commented Jan 18, 2021

Sorry, what's the difference between filesystem root and document root?
Able to illustrate with an example? Does ->setBasePath() play a role here?

Thank you.

@halfpastfouram
Copy link

Filesystem root is the highest level the user can reach on the filesystem. Usually: /.
Document root is the directory that is configured in the webserver (apache, nginx) that is served to the public, for instance /var/www/myapp/htdocs.

@bsweeney
Copy link
Member

bsweeney commented Jan 18, 2021

To follow up on that, setBasePath is relevant only in regards to relative paths, something like "images/image.png". Anything starting with a root-path string "/" or "" is treated as an absolute path and prepending of the base is not done.

@bilogic
Copy link

bilogic commented Jan 24, 2021

Got it thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants