Loading ...
Sorry, an error occurred while loading the content.

need help to open fdf in browser using php

Expand Messages
  • birgunj birgunj
    i want to fill the pdf form field with php script.for this i created the fdf document which fill the pdf form filed. but i want to open the fill pdf form field
    Message 1 of 1 , Nov 2, 2008
      i want to fill the pdf form field with php script.for this i created the fdf document which fill the pdf form filed.
      but i want to open the fill pdf form field in browser.if we able to open the fdf document in browser ,the filled pdf form automatically open.
      i am sending my code.please provide me any idea or solution.

      <form method="post" action="submit_form.php">
         <tr><td>Enter Your Name</td><td><input type="text" name="Text2" /></td></tr>
         <tr><td>Favorite Color</td><td><input type="text" name="Text3" /></td></tr>
         <tr><td>Age</td><td><input type="text" name="Text4" /></td></tr>
         <b>Comments:</b><br />
         <textarea name="Text5" rows="5" cols="35"></textarea>
        <input type="submit" value="Generate FDF Data" />


          // check that a form was submitted
          if(isset($_POST) && is_array($_POST) && count($_POST)){
              // we will use this array to pass to the createFDF function
              // This displays all the data that was submitted. You can
              // remove this without effecting how the FDF data is generated.
              echo'<pre>POST '; print_r($_POST);echo '</pre>';

                  // the name field was submitted
                  if(empty($_POST['Text2']) || preg_match($pat,$_POST['Text2'])){
                      // no value was submitted or something other than a
                      // number, letter or space was included
                      die('Invalid input for Text2 field.');
                      // if this passed our tests, this is safe
                      // Why this? What if someone is spoofing form submissions
                      // to see how your script works? Only allow the script to
                      // continue with expected data, don't be lazy and insecure ;)
                      die('You did not submit the correct form.');
                  // Check your data for ALL FIELDS that you expect, ignore ones you
                  // don't care about. This is just an example to illustrate, so I
                  // won't check anymore, but I will add them blindly (you don't want
                  // to do this in a production environment).
                  // I wanted to add the date to the submissions
                  $data['Text1']=date('Y-m-d H:i:s');
                  // if we got here, the data should be valid,
                  // time to create our FDF file contents
                  // need the function definition
                  require_once 'createFDF.php';
                  // some variables to use
                  // file name will be <the current timestamp>.fdf
                  // the directory to write the result in
                  // need to know what file the data will go into
                  // generate the file content

                  // this is where you'd do any custom handling of the data
                  // if you wanted to put it in a database, email the
                  // FDF data, push ti back to the user with a header() call, etc.

                  // write the file out
                      echo $fdf_file,' written successfully.';
                      die('Unable to create file: '.$fdf_dir.'/'.$fdf_file);
                  //$fdf= fdf_open($tfile);
                  //header("Content-type: application/vnd.fdf");
                  //header('Content-type: application/vnd.fdf');
                  //header('Content-Disposition: inline; filename=1225606224.fdf');
                  header("Content-type: application/vnd.fdf");
      $fp = fopen("1225606224.fdf", "r");
              echo 'You did not submit a form.';


      KOIVI HTML Form to FDF Parser for PHP (C) 2004 Justin Koivisto
      Version 2.1.2
      Last Modified: 9/12/2005

          This library is free software; you can redistribute it and/or modify it
          under the terms of the GNU Lesser General Public License as published by
          the Free Software Foundation; either version 2.1 of the License, or (at
          your option) any later version.

          This library is distributed in the hope that it will be useful, but
          WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
          or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
          License for more details.

          You should have received a copy of the GNU Lesser General Public License
          along with this library; if not, write to the Free Software Foundation,
          Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

          Full license agreement notice can be found in the LICENSE file contained
          within this distribution package.

          Justin Koivisto

      *   createFDF
      *   Takes values submitted via an HTML form and fills in the corresponding
      *   fields into an FDF file for use with a PDF file with form fields.
      *   @param  $file   The pdf file that this form is meant for. Can be either
      *                   a url or a file path.
      *   @param  $info   The submitted values in key/value pairs. (eg. $_POST)
      *   @result Returns the FDF file contents for further processing.
      function createFDF($file,$info){
          $data="%FDF-1.2\n%âãÏÓ\n1 0 obj\n<< \n/FDF << /Fields [ ";
          foreach($info as $field => $val){
                  foreach($val as $opt)
          $data.="] \n/F (".$file.") /ID [ <".md5(time()).">\n] >>".
              " \n>> \nendobj\ntrailer\n".
              "<<\n/Root 1 0 R \n\n>>\n%%EOF\n";
          return $data;


    Your message has been successfully submitted and would be delivered to recipients shortly.