note 44111 added to ref.pdf
| From: | arjen at queek dot nl | Date: | Thu, 15 Jul 2004 11:50:48 +0000 |
| Subject: | note 44111 added to ref.pdf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73287@lists.php.net to get a copy of this message | ||
If you prefer a OO-approach to the PDF-functions, you can use this snippet of code (PHP5 only! and
does add some overhead). It's just a "start-up", extend/improve as you wish...
You can pass all pdf_* functions to your object and stripping pdf_ of the function name. Plus, you
don't have to pass the pdf-resource as the first argument.
For example:
<?php
pdf_show($pdf, $text); // Where $pdf is your pdf-resource
?>
Can become:
<?php
$pdf->show($text); // Where $pdf is your PDF-object
?>
Code:
<?php
class PDF {
private $pdf;
/* public Void __construct(): Constructor */
public function __construct() {
$this->pdf = pdf_new();
}
/* public Mixed __call(): Re-route all function calls to the PHP-functions */
public function __call($function, $arguments) {
// Prepend the pdf resource to the arguments array
array_unshift($arguments, $this->pdf);
// Call the PHP function
return call_user_func_array('pdf_' . $function, $arguments);
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.pdf.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44111
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44111&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44111&report=yes
Search -- http://master.php.net/manage/user-notes.php