Código PHP:
$show_currency_symbol = PDF_get_pdi_parameter($this->p, "vdp/Blocks/$blockname/Custom/show_currency_symbol", $blockcontainer, $page, 0);
if ($key == 'deal_stock_price_per_share') {
$number_decimals = 3;
} else {
$number_decimals = 0;
}
if ($show_currency_symbol == 'no') {
$temp_value = number_format($data[$key], $number_decimals);
} else {
$temp_value = CURRENCY_SYMBOL_PRINT . ' ' . number_format($data[$key], $number_decimals);
}
}
} elseif ($value['field_value_type'] == 'date') {
$temp_value = date("F d, Y", strtotime($data[$key]));
} elseif ($value['field_value_type'] == 'timestamp') {
$temp_value = date("D d, M Y, h:i", $data[$key]);
} elseif (($value['field_type'] == 'select' && $value['field_select_type'] == 'foreign_key') ||
($value['field_type'] == 'hidden' && isset($value['field_select_type']) && $value['field_select_type'] == 'foreign_key') ) {
$sub_query_sql = null;
$show_boolean = PDF_get_pdi_parameter($this->p, "vdp/Blocks/$blockname/Custom/show_boolean", $blockcontainer, $page, 0);
if ($show_boolean == 'yes' && isset($value['field_select_boolean_name'])) {
$sub_query_sql .= 'select ' . $value['field_select_boolean_name'] . ' from ' . $value['field_select_foreign_key_table'] . ' ';
} else {
$sub_query_sql .= 'select ' . $value['field_select_foreign_key'] . ' from ' . $value['field_select_foreign_key_table'] . ' ';
}
$sub_query_sql .= ' where ' . $value['field_select_foreign_key_serial'] . '=\'' . $data[$key] . '\'';
$rs_sub = $this->conn->Execute($sub_query_sql);
if (!$rs_sub || $rs_sub->RecordCount() != 1) {
// This means the record was not found
// So we print nothing
$temp_value = null;
} else {
$sub_data = $rs_sub->fields;
if ($show_boolean == 'yes') {
$temp_value = $sub_data[$value['field_select_boolean_name']];
if ($temp_value == 1) {
$temp_value = $prefix . 'yes' . $suffix;
} else {
$temp_value = $prefix . 'no' . $suffix;
}
} else {
$temp_value = $sub_data[$value['field_select_foreign_key']];
$temp_value = $prefix . $temp_value . $suffix;
}
}
} else {
$temp_value = $prefix . $data[$key] . $suffix;
}
if (!PDF_fill_textblock($this->p, $page, $blockname, $temp_value, "embedding encoding winansi pdiwarning")) {
printf("Warning: couldn't fill block '%s' in '%s'.\n", $blockname, $infile);
}
} elseif ($value['field_type'] == 'textarea') {
$temp_value = stripslashes((trim($data[$key])));
$fontsize = PDF_get_pdi_value($this->p, "vdp/Blocks[$i]/fontsize", $blockcontainer, $page, 0);
$fontname = PDF_get_pdi_parameter($this->p, "vdp/Blocks[$i]/fontname", $blockcontainer, $page, 0);
$lleftx = PDF_get_pdi_value($this->p, "vdp/Blocks[$i]/Rect[0]", $blockcontainer, $page, 0);
$llefty = PDF_get_pdi_value($this->p, "vdp/Blocks[$i]/Rect[1]", $blockcontainer, $page, 0);
$urightx = PDF_get_pdi_value($this->p, "vdp/Blocks[$i]/Rect[2]", $blockcontainer, $page, 0);
$urighty = PDF_get_pdi_value($this->p, "vdp/Blocks[$i]/Rect[3]", $blockcontainer, $page, 0);
$regularfont = PDF_load_font($this->p, $fontname, "winansi", "");
PDF_setfont($this->p, $regularfont, $fontsize);
$leading = $fontsize + 2;
PDF_set_value($this->p, "leading", $leading);
while (PDF_show_boxed($this->p, $temp_value, $lleftx, $llefty, $urightx - $lleftx,
$urighty - $llefty, 'justify', 'blind') != 0) {
$fontsize = $fontsize - 0.5;
PDF_setfont($this->p, $regularfont, $fontsize);
$leading = $fontsize + 2;
PDF_set_value($this->p, "leading", $leading);
}
PDF_show_boxed($this->p, $temp_value, $lleftx, $llefty, $urightx - $lleftx,
$urighty - $llefty, 'justify');
}
}
$i++;
}
}
PDF_end_page($this->p); /* close page */
PDF_close_pdi_page($this->p, $page);
}
}
}
PDF_close_pdi($this->p, $blockcontainer);
PDF_close($this->p); /* close PDF document */
return true;
}
}
function display_pdf ($page_method, $table_name, $table_key_name, $table_key_values) {
header("Content-type: application/pdf");
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'contype') === false) {
$this->p = PDF_new();
if ( !strchr($_SERVER['SERVER_SOFTWARE'], 'Win32')) {
PDF_set_parameter($this->p, 'license', 'L500602-010000');
}
/* open new PDF file; insert a file name to create the PDF on disk */
PDF_open_file($this->p, null);
if ($this->generate_pdf ($page_method, $table_name, $table_key_name, $table_key_values)) {
//$buf = PDF_get_buffer($this->p);
//$len = strlen($buf);
header("Content-Disposition: inline; filename=tp1.pdf");
print PDF_get_buffer($this->p);
PDF_delete($this->p); /* delete the PDFlib object */
return true;
} else {
PDF_delete($this->p); /* delete the PDFlib object */
return false;
}
}
}
function generate_pdf_file ($page_method, $table_name, $table_key_name, $table_key_values) {
$filename = '/tmp/tp1_' . str_replace(',', '_', $table_key_values . '.pdf');
$this->p = PDF_new();
PDF_set_parameter($this->p, 'license', 'L500602-010000');
/* open new PDF file; insert a file name to create the PDF on disk */
PDF_open_file($this->p, $filename);
if ($this->generate_pdf ($page_method, $table_name, $table_key_name, $table_key_values)) {
PDF_delete($this->p); /* delete the PDFlib object */
return $filename;
} else {
PDF_delete($this->p); /* delete the PDFlib object */
return false;
}
}
}
?>