Load extension, open a PDF, add a font, modify PDF in memory and send
it to browser:
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$ext_name="libpdf_php.so";
if (!extension_loaded($ext_name) && !@dl($ext_name))
{
?>
<table width="100%" border="0"><tr><td align="center">
<table style="border: solid #f0f0f0 2px;"><tr>
<td valign="middle" style="padding: 20px; margin: 0px;">
<p style="font-family: arial; font-size: 12px; ">
<b>Sorry,</b><br>
<br>
A PDF can not be generated right now.<br>
The administrator has been informed and will fix this as
soon as possible.<br>
Please try again later.
</p>
</td></tr></table>
</td></tr></table>
<?php
mail('admin@domain.com','Error: PDFLib not found',
'Called by script:\n '.$SCRIPT_FILENAME.'?'.$QUERY_STRING,
"From: warnings@domain.com\n");
exit;
} srand(microtime()*10000);
$usnr= gmdate("Ymd-His-").rand(1000,9999).'-';
$pdf_file=$usnr.'result.pdf';
$src_file='source.pdf';
$pdf = pdf_new();
pdf_open_file($pdf);
pdf_set_parameter($pdf, 'serial', 'if-you-have-one');
pdf_set_parameter($pdf, 'FontAFM', 'TradeGothic=Tg______.afm');
pdf_set_parameter($pdf, 'FontOutline', 'TradeGothic=Tg______.pfb');
pdf_set_parameter($pdf, 'FontPFM', 'TradeGothic=Tg______.pfm');
$src_doc =pdf_open_pdi($pdf,$src_file,'', 0);
$src_page =pdf_open_pdi_page($pdf,$src_doc,1,'');
$src_width =pdf_get_pdi_value($pdf,'width' ,$src_doc,$src_page,0);
$src_height=pdf_get_pdi_value($pdf,'height',$src_doc,$src_page,0);
pdf_begin_page($pdf, $src_width, $src_height);
{
pdf_place_pdi_page($pdf,$src_page,0,0,1,1);
pdf_close_pdi_page($pdf,$src_page);
pdf_set_font($pdf, 'TradeGothic', 8, 'host');
pdf_show_xy($pdf, 'Now: '.gmdate("Y-m-d H:i:s"),50,50);
}
pdf_end_page($pdf);
pdf_close($pdf);
$pdfdata = pdf_get_buffer($pdf); $pdfsize = strlen($pdfdata); header('Content-type: application/pdf');
header('Content-disposition: attachment; filename="'.$pdf_file.'"');
header('Content-length: '.$pdfsize);
echo $pdfdata;
exit; ?>