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

dompdf 1.0.2 does not print images #2431

Closed
cperrot opened this issue Apr 8, 2021 · 16 comments
Closed

dompdf 1.0.2 does not print images #2431

cperrot opened this issue Apr 8, 2021 · 16 comments
Labels

Comments

@cperrot
Copy link

cperrot commented Apr 8, 2021

I have tried with local path to load images and with isRemoteEnabled as well.

It does not load under any circumstances the image.
changed as well from gif to jpg

// CONFIGURATION
$pdfOptions = new Options();
$pdfOptions->set('isRemoteEnabled', true);
//$pdfOptions->set('isHtml5ParserEnabled', true);
$pdfOptions->set("a4", "portrait");

$dompdf = new Dompdf($pdfOptions);
$dompdf->load_html($html);
$dompdf->render();
@cperrot
Copy link
Author

cperrot commented Apr 8, 2021

I even tried the local filename /var/www/img/logo.jpg
with no luck

@maciej-laskowski
Copy link

@cperrot We had similar issues and ended up converting images to base64 and then using them in templetes like so <img src="{{ logoBase64 }}"/>. Of course this is more like a workaround that does not scale well if you have many images.

@bsweeney
Copy link
Member

bsweeney commented Apr 9, 2021

Can you post a sample of the HTML + CSS?

@SignalWhisperer
Copy link

I managed to make it work by removing the leading / in the HTML image source (and for stylesheets).
<img src="/assets/logo.png" /> --> <img src="assets/logo.png" />

It seems that dompdf thinks the leading / is for an absolute path, when for web it is just relative to the root of the website.

@SignalWhisperer
Copy link

The fix is available in this pull request: #2256
A chroot is expected to have / point to the base of the chroot, not to the base of the actual filesystem.

@bsweeney
Copy link
Member

chroot in Dompdf has always been used as a validation not a path adjustment. Thank you for helping clarify for me that the option is poorly named. I think we should fix that and at the same time add actual chroot-like functionality. It's a breaking change so it'll have to be included in a major release.

@SignalWhisperer
Copy link

In docker-compose, I know they use "context" as a validation, similar to how "chroot" is used in Dompdf, if that can give you ideas on terminology to use.

I think most of the confusion also comes from the expected behavior, where it is expected to act like a web browser rather than a filesystem traversal system. This is especially confusing given we are dealing with HTML files in a PHP context, where one would want to generate a page using a view system (such as Smarty for example) and then create a PDF output of it (such as generating a personalized certificate for download).

@romanown
Copy link

i replaced the file src/Image/Cache.php in new vwrsion by old version from 10/10/2017.

@romanown
Copy link

to try reade #2435

@Nexample-G
Copy link

Follow This

https://youtu.be/R3OhMI9P4-s

@romanown
Copy link

romanown commented Jul 6, 2021

this makes the algorithm not work correctly. I removed all the new code. I downloaded the old file instead. I do not have this mechanism. so I don't have this problem now. I don't need this new mechanism in the code. therefore, I have no need to make such changes. moreover, these changes affect security. youtube is full of such videos. but my decision to exclude all new code seems to me safer than always allowing it. thanks.

@Nexample-G
Copy link

Nexample-G commented Jul 6, 2021 via email

@romanown
Copy link

romanown commented Jul 6, 2021

I watched the video before I wrote the message. the video changes the operation of the condition. thus, the code will not work correctly according to the idea of the creator. which theoretically can be considered equal to the fact that this check is missing. this is also equal to deleting the verification code. previously, this check was not carried out. I replaced the new file with an old one that did not have a check. theoretically, our actions on the final result are equal.

@romanown
Copy link

romanown commented Jul 6, 2021

we will wait for the creator to release a new version with a fix.

@Nexample-G
Copy link

Nexample-G commented Jul 6, 2021 via email

@bsweeney
Copy link
Member

bsweeney commented Jul 6, 2021

The OP hasn't responded and the issue introduced with the changes to how the chroot option is handled is sufficiently documented. If you have further questions post in the discussion forum or open a new issue for a suspected bug.

@bsweeney bsweeney closed this as completed Jul 6, 2021
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

6 participants