diff --git a/fillpdf.module b/fillpdf.module index b38a16379324891787bb3686f7011f5c00401303..2a52ae42dba3f21e71cc3cd2193e5c1e0e83019c 100644 --- a/fillpdf.module +++ b/fillpdf.module @@ -330,6 +330,12 @@ function fillpdf_parse_uri($uri = NULL) { $context = fillpdf_link_to_stub_context($uri); fillpdf_merge_pdf($context['fid'], $context['nids'], $context['webforms'], $context['sample'], $context['force_download'], FALSE, $context['flatten'], TRUE, $context['uc_order_ids'], $context['uc_order_product_ids'], $context['entity_ids']); + + // Normally, fillpdf_merge_pdf() calls fillpdf_merge_perform_pdf_action() + // which send the PDF to the browser and calls drupal_exit(). If there is an + // error, it will not exit. Returning empty string ensures that a page is + // rendered on which to display error messages. + return ''; } /** @@ -763,6 +769,10 @@ function fillpdf_merge_pdf($fid, $nids = NULL, $webform_array = NULL, $sample = } $data = fillpdf_execute_merge($method, $fields, $fillpdf_info, 'url', $flatten, $image_data); + if (!$data) { + return; + } + if (!empty($webform['webform'])) { $node = $webform['webform']; } @@ -1092,6 +1102,11 @@ function fillpdf_merge_perform_pdf_action($fillpdf_object, $action = 'download', return; } + // If the PDF is empty, return. + if (!$pdf_data) { + return; + } + // Generate the filename of downloaded PDF from title of the PDF set in // admin/structure/fillpdf/%fid. $output_name = _fillpdf_process_filename($pdf_info->title, $token_objects); @@ -1554,6 +1569,9 @@ function fillpdf_execute_merge($method, array $fields, $fillpdf, $mode = 'url', if ($data === FALSE) { $error = t('pdftk not properly installed. No PDF generated.'); } + elseif (!$data) { + $error = t('Error with pdftk. No PDF generated.'); + } if ($error) { drupal_set_message($error, 'error'); watchdog('fillpdf', $error, array(), WATCHDOG_ERROR);