You are here

function webform2pdf_submission_download_pdf in Webform2PDF 7.4

Same name and namespace in other branches
  1. 6.2 includes/webform2pdf.download.inc \webform2pdf_submission_download_pdf()
  2. 6 webform2pdf.module \webform2pdf_submission_download_pdf()
  3. 7.3 includes/webform2pdf.download.inc \webform2pdf_submission_download_pdf()
1 call to webform2pdf_submission_download_pdf()
webform2pdf_url_decode in includes/webform2pdf.download.inc
1 string reference to 'webform2pdf_submission_download_pdf'
webform2pdf_menu in ./webform2pdf.module
Implements hook_menu().

File

includes/webform2pdf.download.inc, line 13
Implemented menu path: node/%webform_menu/webform-results/downloadpdf node/%webform_menu/submission/%webform_menu_submission/downloadpdf

Code

function webform2pdf_submission_download_pdf($node, $submission, $output_type = 'I') {
  $output_types = array(
    'I',
    'D',
    'S',
  );
  if (in_array($output_type, $output_types)) {
    $template = _webform2pdf_get_template($node->nid);
    $pdf = theme('webform2pdf_pdf_init', array(
      'node' => $node,
      'template' => $template,
    ));
    if (!empty($pdf)) {
      $pdf = theme('webform2pdf_pdf_header', array(
        'pdf' => $pdf,
        'node' => $node,
        'template' => $template,
      ));
      $pdf = theme('webform2pdf_pdf_footer', array(
        'pdf' => $pdf,
        'node' => $node,
        'template' => $template,
      ));
      $pdf = theme('webform2pdf_pdf_page', array(
        'pdf' => $pdf,
      ));

      // todo: @deprecated deprecated since version 5.9.089 (2011-06-13)
      if (method_exists($pdf, 'AliasNbPages')) {

        // initialize document
        $pdf
          ->AliasNbPages();
      }
      $page = theme('webform2pdf_content', array(
        'node' => $node,
        'submission' => $submission,
        'template' => $template,
      ));
      $template['pages'] = explode('%pagebreak', $page);
      $pdf = theme('webform2pdf_pdf_content', array(
        'pdf' => $pdf,
        'node' => $node,
        'template' => $template,
      ));

      // reset pointer to the last page
      $pdf
        ->lastPage();
      $filename = theme('webform2pdf_filename', array(
        'node' => $node,
        'submission' => $submission,
      ));
      switch ($output_type) {
        case 'S':
          return $pdf
            ->Output($filename, 'S');
          break;
        case 'I':

          // http header
          drupal_add_http_header('Content-Type', 'application/pdf');
          drupal_add_http_header('Cache-Control', 'public, must-revalidate, max-age=0');

          // HTTP/1.1
          drupal_add_http_header('Pragma', 'public');
          drupal_add_http_header('Content-Disposition', 'inline; filename="' . $filename . '";');
          break;
        case 'D':
          drupal_add_http_header('Content-Description', 'File Transfer');
          drupal_add_http_header('Cache-Control', 'public, must-revalidate, max-age=0');

          // HTTP/1.1
          drupal_add_http_header('Pragma', 'public');
          drupal_add_http_header('Content-Type', 'application/pdf');

          // use the Content-Disposition header to supply a recommended filename
          drupal_add_http_header('Content-Disposition', 'attachment; filename="' . $filename . '";');
          drupal_add_http_header('Content-Transfer-Encoding', 'binary');
          break;
      }

      // Close and output PDF document
      die($pdf
        ->Output($filename, 'S'));
    }
  }
}