note 20245 added to ref.pdf

From: Date: Wed, 27 Mar 2002 14:56:44 +0000
Subject: note 20245 added to ref.pdf
Groups: php.notes 
Request: Send a blank email to php-notes+get-28275@lists.php.net to get a copy of this message
Load extension, open a PDF, add a font, modify PDF in memory and send it to browser: <?php // no cache headers: 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"; // libpdf_php.so is the PDFLIB for SunOS by "PDFlib GmbH" // visit http://www.pdflib.com // if the extension is not automatically loaded by Apache // dl() will try to load it on demand: 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> &nbsp;<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; } // verify that extension is usable // unique serial number: srand(microtime()*10000); $usnr= gmdate("Ymd-His-").rand(1000,9999).'-'; $pdf_file=$usnr.'result.pdf'; $src_file='source.pdf'; // create pdf object $pdf = pdf_new(); pdf_open_file($pdf); pdf_set_parameter($pdf, 'serial', 'if-you-have-one'); // fonts to embed, they are in the folder of this file: pdf_set_parameter($pdf, 'FontAFM', 'TradeGothic=Tg______.afm'); pdf_set_parameter($pdf, 'FontOutline', 'TradeGothic=Tg______.pfb'); pdf_set_parameter($pdf, 'FontPFM', 'TradeGothic=Tg______.pfm'); // load the source file: $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); { // place the sourcefile to the background of the actual page: pdf_place_pdi_page($pdf,$src_page,0,0,1,1); pdf_close_pdi_page($pdf,$src_page); // modify the 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); // prepare output: $pdfdata = pdf_get_buffer($pdf); // to echo the pdf-data $pdfsize = strlen($pdfdata); // IE requires the datasize // real datatype headers: header('Content-type: application/pdf'); header('Content-disposition: attachment; filename="'.$pdf_file.'"'); header('Content-length: '.$pdfsize); echo $pdfdata; exit; // keep this one so no #13#10 or #32 will be written ?> -- http://www.php.net/manual/en/ref.pdf.php http://master.php.net/manage/user-notes.php?action=edit+20245 http://master.php.net/manage/user-notes.php?action=delete+20245 http://master.php.net/manage/user-notes.php?action=reject+20245

« previous php.notes (#28275) next »