From: <mi...@us...> - 2003-11-29 05:32:18
|
Update of /cvsroot/egroupware/phpgwapi/inc In directory sc8-pr-cvs1:/tmp/cvs-serv14029 Added Files: Tag: acl class.pdf.inc.php Log Message: new class, pending integration --- NEW FILE: class.pdf.inc.php --- <?php /**************************************************************************\ * eGroupware - PDFLib creation class * * (C) 2001-2003 Advanced Internet Designs Inc. <fo...@pr...> * * ------------------------------------------------------------------------ * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ /* $Id: class.pdf.inc.php,v 1.1.2.1 2003/11/29 05:32:15 milosch Exp $ */ putenv('PDFLIBRESOURCE=' . PHPGW_SERVER_ROOT . SEP . 'phpgwapi' . SEP . 'fonts' . SEP . 'PSres.upr'); class pdf { var $pdf, $pw, $ph, $pg_num, $pg_title, $hmargin, $wmargin, $y, $fonts; function pdf($author, $title, $subject, $page_type='letter', $hmargin=15, $wmargin=15) { $this->pdf = pdf_new(); pdf_open_file($this->pdf, ''); pdf_set_info($this->pdf, 'Author', $author); pdf_set_info($this->pdf, 'Title', $title); pdf_set_info($this->pdf, 'Creator', $author); pdf_set_info($this->pdf, 'Subject', $subject); pdf_set_value($this->pdf, 'compress', 9); switch($page_type) { case 'A0': $this->pw = 2380; $this->ph = 3368; break; case 'A1': $this->pw = 1684; $this->ph = 2380; break; case 'A2': $this->pw = 1190; $this->ph = 1684; break; case 'A3': $this->pw = 842; $this->ph = 1190; break; case 'A4': $this->pw = 595; $this->ph = 842; break; case 'A5': $this->pw = 421; $this->ph = 595; break; case 'A6': $this->pw = 297; $this->ph = 421; break; case 'B5': $this->pw = 501; $this->ph = 709; break; case 'letter': default: $this->pw = 612; $this->ph = 792; break; case 'legal': $this->pw = 612; $this->ph = 1008; break; case 'ledger': $this->pw = 1224; $this->ph = 792; break; } $this->hmargin = $hmargin; $this->wmargin = $wmargin; $fonts = array('Courier', 'Courier-Bold', 'Helvetica-Bold', 'Helvetica'); foreach($fonts as $f) { $this->fonts[$f] = pdf_findfont($this->pdf, $f, 'host', false); } } function begin_page($title) { pdf_begin_page($this->pdf, $this->pw, $this->ph); pdf_setlinewidth($this->pdf, 1); $ttl = $title; if($this->pg_num) { $this->pg_num++; $ttl .= ' #'. $this->pg_num; } else { $this->pg_num = 1; } pdf_add_bookmark($this->pdf, $ttl); pdf_setfont($this->pdf, $this->fonts['Courier'], 12); pdf_set_text_pos($this->pdf, $this->wmargin, ($this->ph - $this->hmargin)); $this->pg_title = $title; } function input_text($text,$font='Courier',$fontsize=12) { pdf_setfont($this->pdf, $this->fonts[$font], $fontsize); $max_cpl = pdf_stringwidth($this->pdf, 'w'); $max_cpl = floor(($this->pw - 2 * $this->wmargin) / $max_cpl); foreach($text as $line) { if(strlen($line) > $max_cpl) { $parts = explode("\n", wordwrap($line, $max_cpl, "\n", 1)); $line = $parts[0]; unset($parts[0]); } if(pdf_get_value($this->pdf, 'texty', 0) <= ($this->hmargin + 12)) { $this->end_page(); $this->begin_page($this->pg_title); } pdf_continue_text($this->pdf, $line); if(isset($parts) && count($parts)) { foreach($parts as $p) { if(pdf_get_value($this->pdf, 'texty', 0) <= ($this->hmargin + 12)) { $this->end_page(); $this->begin_page($this->pg_title); } pdf_continue_text($this->pdf, $p); } unset($parts); } } } function draw_line() { $this->y = pdf_get_value($this->pdf, 'texty', 0) - 3; pdf_moveto($this->pdf, $this->wmargin, $this->y); pdf_lineto($this->pdf, ($this->pw - $this->wmargin), $this->y); pdf_stroke($this->pdf); } function add_link($url, $caption) { $oh = pdf_get_value($this->pdf, 'texty', 0); pdf_show($this->pdf, $caption); $y = pdf_get_value($this->pdf, 'texty', 0); $w = pdf_get_value($this->pdf, 'textx', 0); $ow = pdf_get_value($this->pdf, 'textx', 0) - pdf_stringwidth($this->pdf, $caption); pdf_set_border_style($this->pdf, 'dashed', 0); pdf_add_weblink($this->pdf, $ow, $oh, $w,($oh + 12), $url); } function end_page() { pdf_end_page($this->pdf); } function finish($print=False) { pdf_close($this->pdf); pdf_delete($this->pdf); } function fp($fn='test.pdf',$inline=True) { $this->_print($fn,$inline); $this->finish(); } function _print($fn='test.pdf',$inline=True) { $ua = CreateObject('phpgwapi.browser'); $pdf = pdf_get_buffer($this->pdf); $mime = $inline ? 'application/pdf': 'application/octet-stream'; $ua->content_header($fn,$mime,strlen($pdf),True); echo $pdf; unset($ua); return; } } ?> |