I can't get PDF creation to work with pages that have images. What happens is:

  • With dompdf: PDF created, but images missing, and error messages in log (see below)
  • With tcpdf: no PDF created (errors in log and in browser, see below)

(This is with PHP5).

With dompdf (0.5.1), creating a PDF results in the following error messages in the log:

DOMXPath::query() [<a href='function.DOMXPath-query'>function.DOMXPath-query</a>]: Invalid expression in /my/site/drupal/modules/print/dompdf-0.5.1/include/stylesheet.cls.php on line 573.
DOMXPath::query() [<a href='function.DOMXPath-query'>function.DOMXPath-query</a>]: Invalid expression in /my/site/drupal/modules/print/dompdf-0.5.1/include/stylesheet.cls.php on line 573.
Invalid argument supplied for foreach() in /my/site/drupal/modules/print/dompdf-0.5.1/include/stylesheet.cls.php on line 575.
sprintf() [<a href='function.sprintf'>function.sprintf</a>]: Too few arguments in /my/site/drupal/modules/print/dompdf-0.5.1/include/attribute_translator.cls.php on line 291.

With tcpdf, I don't get any PDF at all, the browser window displays

TCPDF error: Can't open image file: /my/site/public_html/system/files/Example640.png

and the log contains the errors:

getimagesize(/my/site/public_html/system/files/Example640.png) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory in /my/site/drupal/modules/print/tcpdf/tcpdf.php on line 3847.
fopen(/my/site/public_html/system/files/Example640.png) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in /my/site/drupal/modules/print/tcpdf/tcpdf.php on line 4071.

(seems like tcpdf has problems with Drupal's "Private" download method? the image is actually in /my/site/private-files/Example640.png, i.e., outside the public_html root directory)

Any ideas? I'd prefer to get dompdf working, as the files generated by tcpdf are insanely huge (>1.5MB for a few lines of text)...

Comments

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

Hi,

Support for the 'private' filesystem has been the subject of recent changes to the code. Can you try the latest dev to check whether the problem has already been fixed?

Thanks,

João

rene_w’s picture

I've tried the latest 6.x development snapshot (2008-Dec-16). What happens now is:

  • With dompdf, there's only one error message left:
    sprintf() [<a href='function.sprintf'>function.sprintf</a>]: Too few arguments in /my/site/drupal/modules/print/dompdf-0.5.1/include/attribute_translator.cls.php on line 291.
    

    but there are still no images in the generated PDF (there's just blank space the approximate size of the image).

  • With tcpdf, the images are inserted now, and there are no more error messages in the log. The generated PDF just isn' very user-friendly: the image is the size of a thumbnail and unreadable (we're talking screenshots here) and the alignment is gone (formatting like centered or float:right seem to be ignored?).
  • However, the site logo is not included in the PDF with either dompdf or tcpdf (this is with the core pushbutton theme and the option "Current theme's logo" enabled).

There are also a number of smaller usability issues with the generated PDF (perhaps these should go into a new comment?):

  • With tcpdf: file size way too big. For a small page without figures, tcpdf creates a 1.5MB file, whereas dompdf manages to put the same content into about 13KB (!) (which even seems to look better).
  • For both tcpdf and dompdf: a list of URL links at the end of the document is created, like for the printer-friendly page (the "Printer-friendly URLs list"). This is not needed for the PDF as links in the text are actually hyperlinks in the PDF. But I haven't found an option to switch this off for PDF generation only? Moreover, while the links in the text are hyperlinks, the URLs at the end of the generated document are not.
  • I'm using the "table of contents" module, which generates links to subsections. But these are not properly translated into the PDF (leading to wrong external URLs).
jcnventura’s picture

Hi,

Thanks for your feedback. Regarding your issues:

1. If TCPDF is able to generate it correctly, but dompdf isn't, then the problem is in dompdf, and there's nothing I can do about it.
2. The small size of images in TCPDF is a known problem when the width and height attributes are not specified. You'll have to specify them to get images with better size. Maybe you can submit an issue in TCPDF's issue queue (see the website from where you downloaded it).
3. I will try to switch to pushbutton and try to see if I can identify a problem.
4. The size of TCPDF-generated files has been solved for some time now. If you go to 'admin/settings/print/pdf', read the description below 'Font Family' on how to solve it.
5. You can disable the URL list in the PDFs on each content type by going to to it's configuration form and disabling it there. A general output format setting might be useful, indeed.
6. Do you mean PDF-internal bookmarks? I don't know whether this is even possible. I will try to take a look at it.

rene_w’s picture

Thanks for the quick response. To follow-up on some of the points:

  1. Regarding dompdf: I'm just wondering if I'm the only one who can't get any images into the PDF? Seems like a rather important use case?
  2. I'll try that. However, adding width/height to all nodes can be really tedious (and problematic in case the images are updated, but the nodes are not). I'll check the sourceforge issue queue for tcpdf. Any idea on the second problem (layout options like centered or float:right ignored)?
  3. Thanks. I should probably mention that I'm still using the default logo that comes with pushbutton -- perhaps replacing it with a custom one will help.
  4. Right, setting this to one of the built-in fonts helped with the size of the created PDFs. Somehow I overlooked this option.
  5. Sorry, I don't get it: for this module, I see only one option to switch the URL list on/off, on the "settings" tab:

    [ ] Printer-friendly URLs list
    If set, a list of the destination URLs for the page links will be displayed at the bottom of the page.

    This effects both the "Printer-friendly" and the "PDF" version. What I'd like is to keep the URL list for the "Printer-friendly" version, but not the PDF version (since it has hyperlinks)?

  6. Right. If this isn't easily possible, a workaround would be to disable all page anchor links (i.e., not only the ones generated by the tableofcontents module).
jcnventura’s picture

Hi,

While I am still here:

1. The private filesystem method wasn't even working until recently (since these libraries will ask for the image directly, Drupal will deny it). The solution was to replace the private URL with a file://real_location_in_file_system URL. If dompdf can't handle such an URL there's really nothing that can be done about it from inside this module.
2. Like other problems, TCPDF doens't handle all the CSS/style options. It's the way it is, and we have to live with it or complain in the issue queue.. :)
3. The pushbutton logo is being correctly displayed (access themes/pushbutton/logo.png to know why :) ).

5. I am not talking about the general override of the URL list setting. I am talking that in each content type configuration (admin/content/types), you'll find an option to disable the URL list in the generated PDF.
6. Indeed, disabling all anchor links in PDF might be the best option.

rene_w’s picture

Re: #5: yep, got it. I know it's even in the documentation, but after staring at the module options page too long it really didn't occur to me to check the content type configuration. Perhaps a simple comment concerning the per-content type configuration (or even a link) under the Printer-friendly URLs list option on the settings page could help people like me who don't breathe "Printer-friendly" configuration all day ;) Something like "If set, a list of the destination URLs for the page links will be displayed at the bottom of the page. Note that you can enable/disable the URL list for each content type individually on the admin/content/types/list page.".

jcnventura’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)
splendidus’s picture

Hi everybody!

I had also an “Invalid Expression” Problem. After several hours of searching and trying, I finally found ‘the’ solution in my case.
The key words are: character encoding, UTF-8, BOM.

I have my styles in a separate css-file, which I link to my php-file.

My editor added a BOM (http://unicode.org/faq/utf_bom.html#BOM) at the beginning of my css-file, while saving it using a UTF-8 encoding.
It was not visible in the editor, but the DOMPDF read it as a ‘’ directly prior to my first style element ‘body’, and ‘body’ is indeed an invalid expression.

Hope this helps somebody…

dampez’s picture

hi can anyone tell me how to display the node images in the pdf?

am using http://drupal.org/project/print

Cheers!

janmech’s picture

in my case dompdf does not display .png - jpeg works fine.

venkatadapa’s picture

Use the dompdf version 6 to fix all image and css issues. For me it is working like a charm.
http://code.google.com/p/dompdf/downloads/detail?name=dompdf_0-6-0_beta1...
In dompdf/dompdf/dompdf_config.inc.php file change error reporting to '0' otherwise you will see
some warnings in the webages those can't be fixed, And these are only warnings so that you can set
to zero to hide the warnings in production sites.
error_reporting('0');

Regards,
Venkat.

rene_w’s picture

Thanks for the tip, I've tried out dompdf-6.0-beta1; it's good, but not good enough for my web site:
- images at the end of a page are simply cut off (they are inserted via the image_assist module)
- code is not printed correctly (blockregion module), all lines are overprinted on one like on an old line printer...
- simple lists (<dl> <dt> <dd>) are not rendered correctly

For now, I'm still using tcpdf (v5_9_034), but it doesn't look good, either:
- all images are "thumbnail-sized"
- blockregion code is rendered with insanely huge spacing
- font encoding problems ("?" for most non-ASCII-characters)

Can't believe it is almost 2011 and this is still so difficult :-(