Closed (fixed)
Project:
Printer, email and PDF versions
Version:
7.x-1.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
14 Jan 2010 at 16:02 UTC
Updated:
22 May 2012 at 13:06 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
mjpg commentedI am having the same problems. Neither the CSS, nor the images are being displayed, even though the PDF is produced OK.
(This is with dompdf 0.5.1).
The print-friendly version is styling OK.
Comment #2
iancawthorne commentedFurther to this. I can add inline styles no problem. The pdf output does not appear to be picking up any css files though.
Comment #3
jcnventuraIf it is affecting the HTML output, I can guarantee that you've configured the module correctly.. However, dompdf is not fully 100% CSS compliant (http://www.digitaljunkies.ca/dompdf/css21.php).
If you want 100% support, try wkhtmltopdf.
João
Comment #4
kvvnn commentedI have the same issue.
It is not a dompdf css-compatibility issue.
Adding
*css code*within the head of the print.tpl.php styles the PDF properly.
But, there is the issue of the image not showing up. I have a feeling we are running into an issue here:
http://www.dashinteractive.net/dompdf/index.php?v=3275633
Will post any results I find.
Comment #5
kvvnn commentedComment #6
kvvnn commentedCheck this out.
In my dompdf install there was a test directory.
If I browse to mysite.com/sites/all/modules/print/lib/dompdf/www/test/examples.php then click on an Image PDF test, the PDF generator works.
So it does indeed seem to be a print module issue.
Comment #7
kvvnn commentedMy investigative report
------------------------------
1) The DOMPDF test pages generate PDF's with images and external stylesheets
2) The Print Module -> Print to PDF link generates a PDF with broken images (red x) and without external stylesheets applied.
3) I found "page not found" errors in my log regarding the external stylesheets and images that Print Module -> Print to PDF link SHOULD be loading. Screenshot attached.
I therefor believe this to be some sort of $path issue. I've been trying for hours to manipulate $path and writing different absolute / relative image paths in print.tpl.php, but nothing has worked yet.
Comment #8
kvvnn commentedNoticing this error now. Notice how the path is incorrect? The $base_url is not being printed in the url.
I wonder of Dompdf's $set_base_path function is not working? Line 136 in print/print_pdf/print_pdf.pages.inc uses this to set the base path, and it appears that the base path is missing according to the errors below.
In a few hours I will try and hack your code to insert Drupal's $base_path into the pathname directly. I hope you come around before then because this could get ugly! Ha.
Cheers.
Comment #9
kvvnn commentedScreenshot for #7 - sorry for all of the separate replies
Comment #10
izmeez commentedsubscribing
Comment #11
kvvnn commentedComment #12
kvvnn commentedComment #13
kvvnn commentedComment #14
kvvnn commented:)
I have this issue fixed on my server. PDF's are now being generated with images and external stylesheets applied.
There were two lines in /print/print_pdf/print_pdf.pages.inc that needed to be removed.
line 136: $dompdf->set_base_path($path);
line 139: $dompdf->set_protocol($protocol);
Can you guys test this? If it works for you, then I'll create a patch.
Thanks,
Comment #15
iancawthorne commentedHi Kevin,
Thanks for looking into this problem.
I tried commenting out both of those lines from #13 but it made no difference for me.
I tried clearing Drupals Cache. Would there be anything else I need to clear?
Comment #16
kvvnn commented1) Use dompdf 0.5.1
2) Insert an img line directly into /print/print.tpl.php file. For Instance, instead of using the default "print $logo" line I have this :
3) Check the printer-friendly page, does the image show up?
4) Use the print-to-pdf link. Does the image show up?
Comment #17
kvvnn commentedAlso : I just noticed that my image is NOT showing the print-friendly version of the node.
Comment #18
mjpg commentedThanks for your work on this.
Commenting out the lines did not fix the problem on my install.
Comment #19
kvvnn commentedmjpg: Have you put an img tag in print.tpl.php file?
This whole issue is being caused by incorrect paths. What commenting out those lines does is makes dompdf (as far as I can tell) consider the $base_path to be www.yoursite.com. This means that any images that go into the print.tpl.php file must have a relative path of "sites/wherever_your_image_is/image.jpg"
Also, only styles that I apply to the head of print.tpl.php are working for me. Here is my print.tpl.php file, which is printing my image and displaying the css (I'm still working out some style issues that I think dompdf is responsible for)
Comment #20
iancawthorne commentedRe: #16
1. Yes I'm using dompdf 0.5.1
2. I've tried inserting an image as you suggest.
3. The printer friendly page shows the image I hard coded in and also the other images which do not load in pdf view
4. Using the pdf view, yes the image hard coded displays. It does not display the other images.
This would confirm you are right that it must be something to do with incorrect paths in the module.
Comment #21
kvvnn commentedSo using that type of path, you see the image on the print-friendly and I do not, and I see the image on the PDF and you do not.
Are you printing nodes?
Use the following three types of image paths to the print.tpl.php file, and see if it helps:
Hmmmmm......
I'm assuming that our different results are due to different server configurations. What kind of server are you on?
Also, are you using the standard dompdf config (in /print/lib/dompdf) file or did you edit it?
Comment #22
iancawthorne commentedNot sure if my post was a bit mis-leading. I CAN see the image in pdf view when entered in the print.tpl as
It is the other images such as site logo and within the node that do not display in pdf view.
All images display fine within the printer friendly view though.
I am running Apache 2.2.14 and Php 5.2.10.
I haven't changed anything in the dompdf library folder.
Comment #23
kvvnn commentedYeah, I'm having the same issue. Its most definitely a bug regarding $base_path or something in the module.
I am simply resorting to print EVERY image with a direct IMG tag in print.tpl.php, including my header and footer and etc. I haven't tested background images though.
I would prefer just printing the /print/nid view from the browser if it did not print a header and footer every time.
Comment #24
mjpg commentedResults of my tests:
Server is Apache/PHP 5.2
Hard-coding the image (in any path method - rel, abs or url) does not work.
Adding the styles inline does work.
The tmp directory is writable and is being written to OK.
The print version works OK.
I haven't changed anything in the dompdf library folder.
Comment #25
chenhaw commentedI'm using wkhtmltopdf. the printed PDF doesn't shows the image..whatever image will become links appear at footnote. how do i enable the image to appear in pdf?
Comment #26
iancawthorne commentedThis thread is about dompdf not wkhtmltopdf
Comment #27
chenhaw commentedHi djmystik82, i'm posting at here because i think it might be a bug at print modules which effect all 3 3rd party pdf generators.
Comment #28
nmashruwala commentedHi all,
I'm seeing the same corrupted image path links behavior with 6.x-1.10 and tcpdf 4.8.032 on D6.15.
I am posting here because it seems that this issue affects all third party pdf generation tools.
It is inconsistent in that certain pages will give errors like "TCPDF ERROR: [Image] No such file or directory in /var/www/html/drupal/6.13//default/files/imagefile.png" but others will generate without a problem. In the case above, the file is exists (is displayed on the page, can be linked to, etc) but is located at /var/www/html/drupal/6.13/sites/default/files/cbfu-high-level.png
In the cases where I could generate a pdf, the path locations for the images given on the bottom of the pdf page are incorrect. Instead of http://example.com/sites/default/files/imagefile.jpg it shows http://example.com/?q=sites/default/files/imagefile.png. As the CSS and image files also do not render, my guess is that the print module is passing the pdf generator bad file locations.
Please do let me know if you need more detail
Comment #29
cbutera commentedHaving the same issue with version 6.x-1.10. The images are showing up as boxes with red X in them.
Comment #30
mikejonesok commentedSub. Same issues. Broken images in the pdf file.
Comment #31
rubenvarela commentedThis is not limited to Dompdf. I'm currently using wkhtmltopdf and I have the same problems.
Images missing in PDF
Stylesheet not being applied to the rendered PDF
It works fine when printing, but when PDF is selected, it just doesn't render the CSS nor display the images.
I'm using a custom CSS file.
Comment #32
cbrompton commentedI have been struggling with this same issue.
Although, I was reading through the print_pdf.pages.inc file and noticed that there is a coulple spots that refer to img tags and having to make the img elements absolute. I'm no coding genius but it appears that it is trying to append http://yoursite.com to the beginning of every img link.
this is line 41-63 in the file
it appears that this code applies to all of the pdf generators.
perhaps someone could look at this section carefully and see if it is correct?
Comment #33
simonmetacci commentedI found this: http://www.martinvseticka.eu/index.php?sekce=browse&page=160
maybe it helps.
Havn't found time to try it out yet.
Comment #34
mikejonesok commentedDid this work for anyone? This seems to be a serious issues. No fix yet?
Comment #35
kvvnn commentedNo, there is no fix yet. This is the only consolidated thread on the issue, so you can check here on results.
I posted some steps starting at #14 that allowed me to get images in a PDF using the DomPDF library, but the image will not show in print preview (seems its one or the other). The steps I used to allow this did not work for another user, though.
Comment #36
mikejonesok commentedThanks Kevin. I'll check it out and give everyone my results.
Update: It didn't work for me either. If someone knows how to stop the red x boxes from showing up then I would be able to use the pdf of this module until a fix comes out that works for everyone.
Comment #37
schildi commentedmy problem looks similar. Installed is version dompdf_0-6-0_alpha2 and the output of a test page looks as can be seen in the appended image "print_orig". I tried to track down the bug and ended in file image_cache.cls.php, function "resolve_url"
In lines seen above path components are checked to see if the file is a remote one.
Surprisingly it is classified as remote because of the leading protocol - which was appended before!
And when your dompdf config file is set up to reject remote files then an icon named "broken_image" is set as a placeholder for the image.
in file dompdf_config.inc.php setting
solved THIS problem for me.
There seems still to be a problem remaining regarding fonts or CSS. See attached images
Comment #38
mikejonesok commentedThanks schildi! You solved the problem for me. A very simple "work-around" fix.
Comment #39
iancawthorne commentedI can also confirm that #37 worked for me too.
Line 334 of dompdf_config.inc.php
Comment #40
schildi commentedand please don't handle the hints above as a bug fix. It's just a work around!
Developers of the module probably expected that local files don't have a protocol in front of the URL (but file://). So the question still is: Why are file paths expanded this way?
Comment #41
jmroth commentedOn my installation with print 6.x-10 and dompdf-0.5.1 facts are:
- print preview works fine
- pdf generation generates [X] where images should be
The HTML used to generate the PDF also looks fine (tested using debug output).
./print_pdf/print_pdf.pages.inc:165:echo($html);
So the culprit must be in dompdf, and this is true:
in image_cache.cls.php we have around line 110:
but on my system allow_url_fopen is off (PHP setting, security risk). <-- (!)
Setting it do "on" helps, although I would simply recommend not using a remote image then, instead use a relative path:
so instead of http://www.yourdomain.com/drupal/sites/www.yourdomain.com.drupal/themes/... (or alike)
just use 'themes/mytheme/logosmall.jpg' as the path.
This however is not possible since a URL is generated in any case as has been mentioned before.
Therefore I have made the following patch to the module at print.pages.inc around line 50:
I have extended "if ($file_downloads == FILE_DOWNLOADS_PRIVATE) {"
with an else block:
faulty patch removed -- see #45
which will now also convert the path to (public) files for the local domain to file:/// i.e. the pdf will generate correctly if LOCAL files are included and allow_url_fopen is off. Note: it will *not* generate images correctly that lie under the local domain but are not managed by Drupal (in case you have drupal running in a subdirectory and link to files in the parent directory, i.e. outside of $base_url).
As another note: on multisite installs with PHP as a fastcgi I don't like the hardcoded /tmp setting.
Change:
./lib/dompdf-0.5.1/dompdf_config.inc.php:73:define("DOMPDF_TEMP_DIR", sys_get_temp_dir());
./lib/dompdf-0.5.1/lib/class.pdf.php:4733: $tmpDir = sys_get_temp_dir();
(first check if your version of PHP supports sys_get_temp_dir())
JM
Comment #42
schildi commentedI first expected that all this logic should be done in the callback function _print_rewrite_urls (file print.pages.inc). But it looks that lines below "preg_replace_callback" - the "if ($file_downloads ==" part - does some correction to modification done by function _print_rewrite_urls.
OK, when applying the patch you provided (and reverting to DOMPDF_ENABLE_REMOTE=false) the problem raises again. The reason is that in my configuration file_downloads is set to FILE_DOWNLOADS_PRIVATE.
Obviously this is not the complete story.
Looking at your proposals:
* do you really mean directory conf_path in the replacement pattern?. Please check
* patch doesn't help at least when FILE_DOWNLOADS_PRIVATE is set
* DOMPDF_TEMP_DIR: done in dompdf-0.6x
May be someone can help me in my lack of comprehension:
* all text / images shown to a user by the print module should also be contained in the PDF version
* the print module does not distinguish between different image sources (PRIVATE / PUBLIC)
So, why should print_pdf introduce another level of security - which can collide with existing ones - by allowing / disallowing access to certain files? Isn't it enough to prefix local paths with "file://" ?
And shouldn't this logic be moved to function _print_rewrite_urls ?
Comment #43
cbrompton commentedWell, the "work-around" seemed to work for me posted #37.
But, it is a "work-around".
I cannot seem to get the else block in # 41 to work.
I hope this can be worked out as I see that it has become a very large security problem.
Comment #44
jmroth commented-- as a reply to #42 --
Sorry it took me a while -- I was busy ...
Concerning conf_path(): In the PUBLIC case I guess files don't need to be under 'files', but they of course can be, that's why I keep that more general in my setup -- feel free to change.
Obviously, my patch does nothing to the PRIVATE case, the problem seems to be FILE_DOWNLOADS_PRIVATE, not DOMPDF_ENABLE_REMOTE. Why do you set the latter one to disabled anyway? Better disallow allow_url_fopen in the first place. Anyway that shouldn't matter and I don't know where the error is. Probably something does not get correctly translated to the real path in the PRIVATE case on your system.
It looks as long as the path in the url is /system/files/something it should work... I tried it on a new install and it did. (see attachment which is a screenshot of the produced PDF)
They had better be ;-)
It doesn't, maybe your PHP configuration does as I noted in comment 41, since print_pdf (or more exactly: dompdf) involves retrieving remote files (which can be disabled in PHP) whereas print itself does not.
Yes it is, since that will no longer be classified as "remote" in dompdf, but for that, this remapping has to work... Put some debug code somewhere in your "if ($file_downloads == FILE_DOWNLOADS_PRIVATE) {" block and see if it actually does translate everything hxxp://XXXXX/system/files/YYY into file://(file_directory_path)/YYY
Someone with a broader perspective on these things should maybe have a look...
Comment #45
jmroth commented-- as a reply to #43 --
I am meanwhile using another patch
I don't remember what was wrong with the first one, but one can see in the attachment that it works for a public file. (compare this to the previous comment's attachment where the screenshot for private download method is shown).
NoteThis seems to be a remedy to the images problem. How to make CSS work: no idea.
Comment #46
sjpatrick commented1) Bump...
2) Tested #37, works. (Turned around and undid it for noted security reasons.)
3) Tested patch #45: Code patch made no apparent difference, though I have absolutely no idea what is is you're trying to tell us to do in your public.png.
Comment #47
jmroth commented@sjpatrick
Image in #44 is supposed to show that it works for private downloads.
Image in #45 is supposed to show that it works for public download method.
Comment #48
Nathan Obral commentedJM, I tried this patch, as well as all of the other possible ones on this thread, for well over eight hours straight with absolutely no success whatsoever. I even went so far as to uninstall and reinstall DOMPDF's 5.1 version, because upgrading to their version 6.0 beta produced the white screen of death.
I really need help here... my problem is virtually the same as outlined by everyone else (it produces a passable PDF, but has [x] in place of the images with no CSS support).
The PHP page:
http://lcccradio.mudmagic.com/?q=talent
Rendered in Print Preview (pardon the pop-up window)
http://lcccradio.mudmagic.com/?q=print/talent
Rendered in DOMPDF:
http://lcccradio.mudmagic.com/?q=printpdf/talent
(For the record, yes, I did test to see if DOMPDF could generate images, and yes it does.)
Tinkering with this for virtually forever, I just can't figure out HOW to fix this bug... where do I exactly change the coding, how much needs to be changed, and what coding needs to be erased? The last thing I want to do is to just give up on the PDF option - TCPDF was even worse off for me, and I have no idea how to install wkhtmltopdf.
PS: How do I "subscribe" for further help?
Comment #49
jmroth commentedThe patch from #45 does work for me when the images are located in the site's files folder (which they are when uploaded e.g. using file attachments). It doesn't seem to work for images from anywhere else though.
Comment #50
Nathan Obral commentedOkay, thanks for the clarification. The site itself was imported to and modified with Drupal, so as a result the vast majority of images files are not in "files" folder. I'd rather not have to reload and redirect every single image file, so does this make this Dompdf problem non-repairable?
Comment #51
jmroth commentedI'm sure there is a patch for everything. Feel free to come up with one :)
Comment #52
Nathan Obral commentedIt may take a while to create... I've never really done anything like that before... ;)
Comment #53
selinav commentedHello,
I've also the problem with the library dompdf.
I've patched like in #37. I've ever not the problem with the red X but I've only an icon with the name of the image instead of the image. If I click on the name, the link is good, it opened the image in a new window.
How to do to have the image instead of the icon and the name.
Have you succeed to display images?
More over, what is the unity to use in the CSS files to place block.
I use 1cm~=40px, is it the good way?
Thanks in advance
Comment #54
olbion commentedI was trying to get this to work for a long time, until the obvious struck me. My development server is seperate from the computer I'm working from and I'm working on a test site who's domain is only set in my local hosts file. Well, I forgot to set it up on the host file of the dev server. So, dompdf was trying to get the image using the absolute path but it was actually not there.. duh!
Thought I'd share this if anyone else got stuck similarly.
Comment #55
skilip commentedI can confirm #37 as well. The following patch adds the defines into print_php.module.
Comment #56
Elhu commentedThanks #37, this solved my problem too!
PS: I'm so going to buy you a beer for that !
Comment #57
schildi commentedNice to hear!
But I would sugget you get a glass of a good wine.
Comment #58
jochenh commentedHmm #37 isnt working for me but I am using dompdf-0.5.1 and in the config we have:
define("DOMPDF_ENABLE_REMOTE", true);So that seems to be enabled by default -- maybe I ought to try some of the other PDF generation tools...
- J
Comment #59
usta commentedTCPDF still doesn't work:
TCPDF ERROR: [Image] Unable to get image width and height: /Applications/MAMP/htdocs/_cms/drupal-6.16-DE//default/files/imagecache/ ...The problem seems to occur between the double slashes: instead of "drupal-6.16-DE//default" the URL should read: "drupal-6.16-DE/sites/default".
Comment #60
Anonymous (not verified) commented#37 worked for me, using dompdf 0.6.0 beta1; image now display + PDF now uses print.css.
Thanks, schildi!
Comment #61
dooug commentedThe patch from #55 works for me. I am using dompdf 0.5.1.
Can someone comment on the potential security issues using this patch, mentioned in #43?
Comment #62
quadbyte commented#55 works for me using dompdf 0.6.0 beta1.
Comment #63
FreddieK commentedNeither #37 nor #55 worked for me using Print 6.x-1.10 and dompdf 0.6.0 beta1.
Comment #64
SebCorbin commentedTested. It works, thanks a lot. Port it please :) (dompdf 0.5.1)
Comment #65
sammys commented#55 worked for me with dompdf 0.6.0 beta1 and the trunk snapshot of dompdf. I have also patched it with the following patches:
Thanks for the patch! :)
Comment #66
jcnventuraCommitted to CVS. I had to change the patch considerably, but thanks for the pointer!
João
Comment #68
davidhhuan commentedThrough the comments as above, I have my own way to resolve this problem:
in dompdf_config.inc.php, maybe line 333,
change from:
TO
in print_pdf.pages.inc, maybe line 60-62
I comment the code:
Comment #69
daniel wentsch commentedI also had the problem of images not showing up and was able to fix it as kevin suggested in #14.
But now another issue comes up: I'd like to use an imagecache preset that's only used for pdf creation. When I change cck display settings to use this for the print display, the images don't get generated by imagecache. When the images have already created before they just get used fine by domepdf. It seems, pdf generation doesn't trigger imagecache to start processing images. Anybody aware of this (and maybe there's even a solution I couldn't figure out yet?)
Comment #71
ice5nake commentedI am having the same problem with wkhtmltopdf, strangely enough I was not having the problem with dompdf when I was trying that.
Comment #72
vinnizworld commentedIt may be possible, that your images are put as background-image in your HTML/PHP document. So for the reason print command doesn't support or print the background images / color to the document.
Comment #73
DCanfield commentedAfter working on this for the entire day, and following many of the suggestions above I came to realize (quite by accident) that dompdf would not render .png files. At least it doesn't in my configuration. Switched to .jpg files and all works just fine.
I don't recall seeing that in any of the documentation, and as I said it may be something unique to my configuration. However, if you're having trouble it might be worth trying, ymmv.
Comment #74
Yuri commentedPDF version is still not picking up css/print.css on the latest D7 dev version of this module
Is there still no working patch after two years having this issue?
Comment #75
yngens commentedNot only .png, my installation does not work for .jpg files too.
Comment #76
jcnventuraSee #1230480: Inline the CSS when sending the HTML to TCPDF for problem with CSS includes.