I'm using the module to output PDFs using the mpdf library. In my dev site, it works fine. When I deployed to staging, it doesn't work. URLs like...

mysite.com/printpdf/1234

...redirect to...

mysite.com/1234

And I get this error in my log:

Notice: Undefined variable: pdf in print_pdf_generate_html() (line 551 of /opt/staging/staging.tmei.org/public/sites/all/modules/contrib/print/print_pdf/print_pdf.module).

I believe I have all the module settings and file perms the same in my staging site as they are in my dev site.

Comments

frob’s picture

I am getting this too.

frob’s picture

apparently there is no pdf tool enabled. This could probably use some better error handling.

frob’s picture

save your settings here and it should remove the notice
admin/config/user-interface/print/pdf

RumpledElf’s picture

Wow ok, this is quite the UX issue. And yes, you fix it by going to that path and hitting save but you shouldn't have to go around googling to find that out, when you go to the settings page after installing a library all the right options are pre filled but you still have to hit save.

frob’s picture

Status: Active » Needs review

I have not tested this, but this patch should solve the issue. It will not make things work out of the box, but it will make it not error.

The issue is that this function doesn't return anything.

function print_pdf_generate_html($html, $meta, $filename = NULL, $paper_size = NULL, $page_orientation = NULL) {
  $pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
 
  module_load_include('inc', $pdf_tool[0], $pdf_tool[0] . '.pages');

  $function = $pdf_tool[0] . '_print_pdf_generate';
  if (function_exists($function)) {
    $pdf = $function($html, $meta, $paper_size, $page_orientation);
  }
  if ($filename) {
    return print_pdf_dispose_content($pdf, $filename);
  }

  return $pdf;
}

So I am now just preloading the $pdf variable.

candelas’s picture

@frob saving the settings in admin/config/user-interface/print/pdf made it!! Thanks

jcnventura’s picture

The problem is that the site would become too slow if the check were done before the call to generate the PDF, and after the call it's already too late.

In any case, the administrator is alerted to the exact nature of the problem in the 'status report' page, where it belongs. I will however add the $pdf wrapper suggested here, as it removes the notices from the log.

pianomansam’s picture

Status: Needs review » Needs work

I have not tested this, but this patch should solve the issue. It will not make things work out of the box, but it will make it not error.

Since there isn't a patch and the above code doesn't solve the issue but only suppresses the error, I'm reverting this to needs work.

frob’s picture

Status: Needs work » Fixed

If you check the code you will see that my suggested fix was already applied. The correct status is fixed.

pianomansam’s picture

That's fine, @frob. Since the original PHP notice is fixed, I'll create a separate related ticket about the need to resubmit the admin form in order to make things work.

Status: Fixed » Closed (fixed)

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