When I try to export a Book page to PDF, I get the following error:

Notice: Undefined offset: 1 in _print_pdf_wkhtmltopdf_version() (line 611 of ... /print/print_pdf/print_pdf.module

Comments

maxxer’s picture

same problem

blasthaus’s picture

sub

maxxer’s picture

having better luck with the tcpdf libraries

arafat_aa’s picture

Yes Maxxer,I am using tcpdf tool but the problem is that the borders of the table of the view does not appear in the resulting pdf , any help wil be appreciated

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

I was unable to reproduce this with the current dev of the print module.. DO you still get this error?

kukle’s picture

same error here
Notice: Undefined offset: 1 in _print_pdf_wkhtmltopdf_version() (regel 655 van /.../.../domains/.../public_html/leden/sites/all/modules/print/print_pdf/print_pdf.module).

kukle’s picture

Status: Postponed (maintainer needs more info) » Active

Set to active

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

Can you tell me what's the output of "wkhtmltopdf --version" ?

shawn_smiley’s picture

StatusFileSize
new667 bytes

Here is the output of wkhtmltopdf --version on my mac dev environment:

Name:
  wkhtmltopdf 0.10.0 rc2

License:
  Copyright (C) 2010 wkhtmltopdf/wkhtmltoimage Authors.



  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
  This is free software: you are free to change and redistribute it. There is NO
  WARRANTY, to the extent permitted by law.

Authors:
  Written by Jan Habermann, Christian Sciberras and Jakob Truelsen. Patches by
  Mehdi Abbad, Lyes Amazouz, Pascal Bach, Emmanuel Bouthenot, Benoit Garret and
  Mário Silva.

I've attached a patch that resolved the issue on my machine.

The patch makes the following code change:

    $content = stream_get_contents($pipes[1]);
    $out = preg_match('!.*?(\d+\.\d+\.\d+).*$!m', $content, $matches);

The issue seems to be related to having the call to stream_get_contents() as a direct parameter input on the preg_match function. Moving stream_get_contents() so that it assigns to a variable and then use that variable in preg_match() solved the problem.

jcnventura’s picture

Status: Postponed (maintainer needs more info) » Needs review

Yes, that happens on some cases where PHP creates a race condition.. I'll try your patch, and see if that helps everyone..

jcnventura’s picture

Status: Needs review » Fixed

Thanks for the patch! Added to git.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

altrugon’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta1
Status: Closed (fixed) » Active

I'm working with the patched version (7.x-1.0-beta1) but I still see this error.

I've downloaded the wkhtmltopdf.app option, extract the entire content and copy it into print/lib/wkhtmltopdf and this is what I get:

Output of wkhtmltopdf --version:

Name:
  wkhtmltopdf 0.10.0 rc2

License:
  Copyright (C) 2010 wkhtmltopdf/wkhtmltoimage Authors.



  License LGPLv3+: GNU Lesser General Public License version 3 or later 
  <http://gnu.org/licenses/lgpl.html>. This is free software: you are free to
  change and redistribute it. There is NO WARRANTY, to the extent permitted by
  law.

Authors:
  Written by Jan Habermann, Christian Sciberras and Jakob Truelsen. Patches by
  Mehdi Abbad, Lyes Amazouz, Pascal Bach, Emmanuel Bouthenot, Benoit Garret and
  Mário Silva.

And when I check the result of $matches as follow I get and empty array:

$out = preg_match('!.*?(\d+\.\d+\.\d+).*$!m', $content, $matches);
dpm($matches);
jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

My guess is that $matches is empty because $content is probably also empty.. Can you do a dpm of that one, please?

altrugon’s picture

StatusFileSize
new142.79 KB

You were right jcnventura, $matches is empty too.

I have created an array with all the relevant variables from function _print_pdf_wkhtmltopdf_version(), please see the attached screen-shot to check out the results.

Thank you.

jcnventura’s picture

My guess is that there's something wrong with PHP or the web server configuration that you're not allowed to execute programs.. Also check the error log for any useful info.

altrugon’s picture

I don't have anything on the error logs except the mentioned error and I gave 777 permission to everything inside the library folder.

What else do you think could be wrong on the server?

jcnventura’s picture

Would it be too much to ask you to try this in Linux?

Until Apple offers me a computer capable of running OS X, or allows me to run OS X on any of my existing computers, I simply can't even try to debug this type of problem. And yeah, I know hell will freeze over before they give me one..

Bevan’s picture

I had this problem on ubuntu when I installed wkhtmltopdf with apt-get, which installed an old, unsupported version of the library.

mausolos’s picture

This appears to be my problem, too. Rats. It would be awfully nice if some updated the requirements page to indicate which version(s) of wkhtmltopdf are acceptable.

gianfrasoft’s picture

Same problem here but with tcpdf library:

Notice: Undefined offset: 1 in theme_print_pdf_tcpdf_header() (linea 503 di mysite\sites\all\modules\contrib\print\print_pdf\print_pdf.pages.inc).

jcnventura’s picture

@gianfrasoft: I think I got your problem.. Please try the latest dev, when that is created a few hours from now.

jcnventura’s picture

No further info in two weeks. Closing the issue.

jcnventura’s picture

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

I ran into an issue like this. It turns out MAMP doesn't play well with ImageMagick. This is documented here: http://mikepuchol.com/2010/08/26/getting-mamp-1-9-to-work-with-image-mag...

I did step 8 on that page and got pdf generation on mac via wkhtmltopdf to work.

sudo vi /Applications/MAMP/Library/bin/envvars

Comment the two lines that set and export the path, which look like:

#DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#export DYLD_LIBRARY_PATH
nibo’s picture

Version: 7.x-1.0-beta1 » 7.x-1.2
Priority: Major » Normal
Status: Closed (fixed) » Active

Hi,

I also got the Undefined offset error on theming the tcpd header:

Notice: Undefined offset: 1 in theme_print_pdf_tcpdf_header() (line 514 in /sites/all/modules/print/print_pdf/print_pdf.pages.inc).

The thing is, that I did override the print.tpl.php and removed the div with the class = "print-site_name" since I didn't wanted to output the site_name. But the preg_match() in the theme_print_pdf_tcpdf_header() function is looking exactly for this div to generate the $tpl_site_name variable.

Wouldn't it be better to pass the logo, title and site name in the $vars array?

jcnventura’s picture

Status: Active » Closed (fixed)

See #1865562: PDF Templates missing "print-site_name" are generating errors for a patch that avoids the problem while keeping the current (old) way of preg_match()ing the HTML to get the needed data.. The current code is a lot more template-like, so that info could indeed all be in the $vars array.

Looking back at it, the reason it does such a convoluted scheme is to try to make it easy for themers to change the footer and header of the TCPDF pages, simply by modifying the print.tpl.php. The info is already all in the $vars array.

debra-v’s picture

Category: bug » support

I've been trying to get this to work on both a MAMP installation and a non-MAMP shared hosting server.

Using :
wkhtmltopdf-i386 (wkhtmltopdf-0.11.0_rc1-static-i386)
Drupal 7.21

Error when attempting access to PDF Version:
Notice: Undefined offset: 1 in _print_pdf_wkhtmltopdf_version() (line 711 of /xxxx/xxxx/public_html/drupal/sites/all/modules/print/print_pdf/print_pdf.module).

I have the latest version of print that includes the update listed above and have attempted several config changes (such as the path adjustment for MAMP)
I have verified permissions to the library are '755' and owned by the correct user.

Print config settings have been setup. The Print module detects the existence of wkhtmltopdf.

Not sure what I'm missing, but I cannot get it to work.

Any Suggestions?

.......

Update: Looks like I did not have the correct binary version. I reinstalled the OS X version and it started working. Will reinstall with a diff version on the shared hosting site and see what happens.

bleen’s picture

FWIW I had to follow a similar solution to the one in #25 to resolve this error. I guess the more recent versions of MAMP have a slightly different /Applications/MAMP/Library/bin/envvars file... I had sudo vim /Applications/MAMP/Library/bin/envvars and change this:

if test "x$DYLD_LIBRARY_PATH" != "x" ; then¬
  DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"¬
else¬
  DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib"¬
fi¬
export DYLD_LIBRARY_PATH¬

to

if test "x$DYLD_LIBRARY_PATH" != "x" ; then¬
  DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"¬
else¬
  DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib"¬
fi¬
#export DYLD_LIBRARY_PATH¬