WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Generate FDF files without the pdftk library or php extension.
Categories : PHP, PHP Classes, PDF Click here to Update Your Picture
Juan Jaramillo
Date : Nov 24th 2009
Grade : Be the 1st to grade this Code Example
Viewed : 2210
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Juan Jaramillo
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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