|
|
|
|
|
Need to generate FDFs but can't install the php extension / recompile? I took some code found here:
http://www.weberdev.com/get_example-4344.html
And re-wrote it as a class, which will make it easier to use..
|
<?php
class FdfFile {
private $fdf = null;
public function __construct(){
$this->create();
}
private function create() {
$this->fdf['header'] = "%FDF-1.2\n%????\n1 0 obj \n<< /FDF ";
$this->fdf['trailer'] = ">>\nendobj\ntrailer\n<<\n/Root 1 0 R \n\n>>\n%%EOF";
}
public function setFile($pdfFile) {
$this->fdf['file'] = $pdfFile;
}
public function setTargetFrame($target) {
$this->fdf['target'] = $target;
}
public function setValue($fieldName, $fieldValue) {
$this->fdf['values'] = array_merge($this->fdf['values'], array($fieldName => $fieldValue));
}
public function addDocJavascript($scriptName, $script) {
$this->fdf['docscripts'] = array_merge($this->fdf['docscripts'], array($scriptName => $script));
}
public function setJavascriptAction($fieldName, $trigger, $script) {
$this->fdf['fieldscripts'] = array_merge($this->fdf['fieldscripts'], array($fieldName => array($script, $trigger)));
}
public function save($fdfFile = null) {
$search = array('\\', '(', ')');
$replace = array('\\\\', '\(', '\)');
$fdfStr = $this->fdf['header'];
$fdfStr.= "<< ";
if(isset($this->fdf['file'])) {
$fdfStr.= "/F (".$this->fdf['file'].") ";
}
if(isset($this->fdf['target'])) {
$fdfStr.= "/Target (".$this->fdf['target'].") ";
}
if(isset($this->fdf['docscripts'])) {
$fdfStr.= "/JavaScript << /Doc [\n";
// populate the doc level javascripts
foreach($this->fdf['docscripts'] as $key => $value) {
$fdfStr.= "(".str_replace($search, $replace, $key).")(".str_replace($search, $replace, $value).")";
}
$fdfStr.= "\n] >>\n";
}
if(isset($this->fdf['values']) || isset($this->fdf['fieldscripts'])) {
// field level
$fdfStr.= "/Fields [\n";
if(isset($this->fdf['fieldscripts'])) {
// populate the field level javascripts
foreach($this->fdf['fieldscripts'] as $key => $val) {
$fdfStr .= "<< /A << /S /JavaScript /JS (".str_replace($search, $replace, $val[0]).") >> /T (".str_replace($search, $replace, $key).") >>\n";
}
}
if(isset($this->fdf['values'])) {
// populate the fields
foreach($this->fdf['values'] as $key => $value) {
$fdfStr .= "<< /V (".str_replace($search, $replace, $value).") /T (".str_replace($search, $replace, $key).") >>\n";
}
}
$fdfStr.= "]\n";
}
$fdfStr.= ">>";
$fdfStr.= $this->fdf['trailer'];
if($fdfFile) {
$handle = fopen($fdfFile, 'w');
fwrite($handle, $fdfStr);
fclose($handle);
}else {
return $fdfStr;
}
}
}
?> | |
Example:
| <?php
$fdf = new FdfFile();
$fdf->setFile("http://mydomain.com/mydocument.pdf");
$str = $fdf->save( null );
Header("Content-type: application/vnd.fdf");
die($str);
?> | | |
|
| Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | How To Create a PDF Using PHP Categories : PHP, PDF, PHP Classes, HTML and PHP | | | PDF class - This is a useful class to make a pdf file with php functions. Categories : PHP, PDF, PHP Classes | | | Url To Pdf Report By Remote Application Categories : PHP, PHP Classes, PDF, CURL | | | Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip Categories : Email, Network, PHP, PHP Classes | | | Authorize.net AIM Interface Class v1.0.0 Categories : PHP, PHP Classes, Ecommerce, Payment Gateways | | | Browser Detecor Class Categories : PHP Classes, PHP, HTML | | | filesplit : Split big text files in multiple small ones Categories : PHP, Log Files, Filesystem, PHP Classes | | | A File Browser Class.To Read Drives,Directories and Files .Files writing is also possible Categories : PHP, PHP Classes, Filesystem | | | Specify your connection settings and create a link to a MySQL database. Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides | | | an example of the cyberlib payment class Categories : PHP, PHP Classes, Ecommerce, Credit Cards | | | Filter - A simple class that lets you use multiple functions to create custom filters. Categories : PHP, PHP Classes, Strings | | | Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support Categories : PHP, FTP, Filesystem, PHP Classes, Compression | | | DbObject - A PHP wrapper for working with various databases Categories : Databases, PHP, PHP Classes | | | Simple and fast user authentication Categories : PHP, PHP Classes, Authentication | |
| |
| |
|