|
|
|
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);
?> | | |
|
| PDF class - This is a useful class to make a pdf file with php functions. Categories : PHP, PDF, PHP Classes | | | How To Create a PDF Using PHP Categories : PHP, PDF, PHP Classes, HTML and PHP | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | Url To Pdf Report By Remote Application Categories : PHP, PHP Classes, PDF, CURL | | | Mssql database Manager Categories : PHP, Databases, MS SQL Server, Classes and Objects, PHP Classes | | | Automatic generation of HTML code for a table. OO interface. Can define colspan, rowspan, table style, cell style, and data style. Simple, but
effective. Categories : PHP, PHP Classes, HTML, HTML and PHP | | | Create HTML forms dynamicly using Javascript & PHP Categories : PHP, PHP Classes, Java Script | | | Simple database class Categories : PHP, PHP Classes, MySQL, Databases | | | Recordset Class for MSSQL database Categories : PHP Classes, Databases, PHP, MS SQL Server | | | The GTV.class allows you to extract a value between any HTML tag or between any TEXT on a web page. Categories : PHP, PHP Classes, Regexps | | | HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout. Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs | | | a class for doing payments to a cybercash server
Categories : Ecommerce, Complete Programs, PHP Classes, PHP | | | Freshmeat.net XML-RPC - This class is meant to query Freshmeat for information about registered projects. Categories : PHP, PHP Classes, XML, Web Services | | | Optimized Online users class Categories : PHP, PHP Classes, Sessions | | | Simple usersOnline class - keep track of how many users are online on your site Categories : PHP, PHP Classes, Databases, MySQL | |
|
|