function fillpdf_execute_merge in FillPDF 6
Same name and namespace in other branches
- 7.2 fillpdf.module \fillpdf_execute_merge()
- 7 fillpdf.module \fillpdf_execute_merge()
Utility function to allow other functions to merge PDFs with the various methods in a consistent way.
Parameters
string $method The service or program being used. Possible values: local, remote, pdftk. Currently, only pdftk is supported.:
array $fields The fields to merge into the PDF. Should be retrieved from the {fillpdf_fields} table.:
mixed $fillpdf When in URL mode, this is the record from {fillpdf_forms}. When in Stream mode, this is the PDF data.:
string $mode A special flag to control the behavior of this function. URL mode merges using a PDF on the: file system and Stream mode merges using the value of $fillpdf directly. Possible values: url, stream.
1 call to fillpdf_execute_merge()
- fillpdf_merge_pdf in ./
fillpdf.module - Constructs a page from scratch (pdf content-type) and sends it to the browser or saves it, depending on if a custom path is configured or not.
File
- ./
fillpdf.module, line 508 - Allows mappings of PDFs to site content
Code
function fillpdf_execute_merge($method, $fields, $fillpdf, $mode = 'url', $flatten = TRUE) {
$data = NULL;
// Try to prepare the data so that the $method part can process it without caring too much about merge tool
switch ($mode) {
case 'url':
$filename = $fillpdf->url;
break;
case 'stream':
$filename = file_save_data($fillpdf, file_directory_temp() . '/pdf_data.pdf', FILE_EXISTS_RENAME);
break;
}
switch ($method) {
case 'pdftk':
module_load_include('inc', 'fillpdf', 'xfdf');
// Looks like I'm the first actually to use this! (wizonesolutions)
$xfdfname = $filename . '.xfdf';
$xfdf = create_xfdf(basename($xfdfname), $fields);
// Generate the file
$xfdffile = file_save_data($xfdf, $xfdfname, FILE_EXISTS_RENAME);
// Now feed this to pdftk and save the result to a variable
$data = shell_exec('pdftk ' . escapeshellarg($filename) . ' fill_form ' . escapeshellarg($xfdffile) . ' output - ' . ($flatten ? 'flatten ' : '') . 'drop_xfa');
if ($data === NULL) {
drupal_set_message(t('pdftk not properly installed. No PDF generated.'), 'error');
}
file_delete($xfdffile);
if ($mode == 'stream') {
file_delete($filename);
}
break;
}
if ($data) {
return $data;
}
else {
return FALSE;
}
}