function fillpdf_merge_handle_pdf in FillPDF 7.2
Same name and namespace in other branches
- 7 fillpdf.deprecated.inc \fillpdf_merge_handle_pdf()
Figure out what to do with the PDF and do it.
Parameters
$pdf_info An object containing the loaded record from {fillpdf_forms}.:
$pdf_data A string containing the content of the merged PDF.:
$token_objects An array of objects to be used in replacing tokens.: Here, specifically, it's for generating the filename of the handled PDF.
$action One of the following keywords: default, download, save,: redirect. These correspond to performing the configured action (from admin/structure/fillpdf/%), sending the PDF to the user's browser, saving it to a file, and saving it to a file and then redirecting the user's browser to the saved file.
$force_download If set, this function will always end the request by: sending the filled PDF to the user's browser.
Return value
void
2 calls to fillpdf_merge_handle_pdf()
- fillpdf_merge_pdf in ./
fillpdf.module - fillpdf_rules_action_handle_default in ./
fillpdf.rules.inc - Perform the default action on the PDF. This always ends in a drupal_goto() or a drupal_exit().
File
- ./
fillpdf.module, line 617 - Allows mappings of PDFs to site content
Code
function fillpdf_merge_handle_pdf($pdf_info, $pdf_data, $token_objects, $action = 'download', $force_download = FALSE) {
if (in_array($action, array(
'default',
'download',
'save',
'redirect',
)) === FALSE) {
// Do nothing if the function is called with an invalid action.
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);
if ($action == 'default') {
// Determine the default action, then re-set $action to that.
if (empty($pdf_info->destination_path) === FALSE) {
$action = 'save';
}
else {
$action = 'download';
}
}
// Initialize variable containing whether or not we send the user's browser to
// the saved PDF after saving it (if we are)
$redirect_to_file = FALSE;
// Get a load of this switch...they all just fall through!
switch ($action) {
case 'redirect':
$redirect_to_file = $pdf_info->destination_redirect;
case 'save':
fillpdf_save_to_file($pdf_info, $pdf_data, $token_objects, $output_name, !$force_download, $redirect_to_file);
// FillPDF classic!
case 'download':
drupal_add_http_header("Pragma", "public");
drupal_add_http_header('Expires', 0);
drupal_add_http_header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
drupal_add_http_header('Content-type', 'application-download');
// This must be strlen(), not drupal_strlen() because the length in bytes,
// not in characters, is what is needed here.
drupal_add_http_header('Content-Length', strlen($pdf_data));
drupal_add_http_header('Content-disposition', 'attachment; filename="' . $output_name . '"');
drupal_add_http_header('Content-Transfer-Encoding', 'binary');
echo $pdf_data;
drupal_exit();
break;
}
}