function fillpdf_generate_pdf in FillPDF 5
Generates the PDF ouput based on field values It (1) constructs the XFDF from the form's fields, (2) saves the XFDF to /files/xfdf/x.xfdf, (3) redirects to the servlet at SERVLET_URL which downloads this XFDF, merges it with the user-specified PDF, and returns the output. The SERVLET_URL construct is SERVLET_URL?fid=10&nid=10 where fid is this form's id and nid is the node id from which data will be pulled via tokens.
1 string reference to 'fillpdf_generate_pdf'
- fillpdf_menu in ./
fillpdf.module - Implementation of hook_menu().
File
- ./
fillpdf.module, line 536 - Allows mappings of PDFs to site content
Code
function fillpdf_generate_pdf() {
$fid = $_GET['fid'];
$nid = $_GET['nid'];
if (!$fid) {
return;
}
$fillpdf_info = db_fetch_object(db_query("SELECT title, url FROM {fillpdf_forms} WHERE fid=%d", $fid));
//just give them empty pdf if no nid
if (!$nid) {
header("Location: {$fillpdf_info->url}");
exit;
}
$host = 'http://' . $_SERVER['SERVER_NAME'];
$node = node_load($nid);
$fields = array();
$query = db_query("SELECT * FROM {fillpdf_fields} WHERE fid=%d", $fid);
while ($obj = db_fetch_object($query)) {
$str = token_replace($obj->value, $type = 'node', $object = $node);
$str = preg_replace('|<br />|', '
', $str);
$fields[$obj->pdf_key] = $str;
}
// get the XFDF file contents
include_once drupal_get_path('module', 'fillpdf') . '/xfdf.inc';
$xfdf = createXFDF($fillpdf_info->url, $fields);
$download_name = preg_replace('/[^a-zA-Z0-9_]/', '', $fillpdf_info->title) . '.pdf';
//$download_name = preg_match('|\/[^\/].*$|',$fillpdf_info->url);
$dir = "files/xfdf";
file_check_directory($dir, 1);
$res = file_save_data($xfdf, "xfdf/{$download_name}.xfdf", FILE_EXISTS_REPLACE);
if (!$res) {
return;
}
//couldn't save file
$xfdf_file = $host . '/' . $res;
header("Location: " . SERVLET_URL . "?method=merge&title={$download_name}&pdf={$fillpdf_info->url}&xfdf={$xfdf_file}");
}