Jump to content

Convert .fdf to .pdf


Ty44ler

Recommended Posts

Were you able to resolve this?  This is driving me crazy.  I think I'm at the same point you were when you were seeking help.  Thanks for any help.

 

Which part are you stuck on?

 

I can generate the fdf no problem.  Everything seems to work fine there.  But I can't generate the PDF from there.  Ty44ler adds additional code to the original which I thought would resolve the problem.  I enter that and get syntax error at ?>  Not sure why though.  Thanx for any help though.

Link to comment
Share on other sites

Here's all I do:

 

$fdf_file="CMS".$focus->caseid.".fdf";
$pdf_file="CMS".$focus->caseid.".pdf";
$fdf_dir=".\\pdfFiles\\";
exec('pdftk cms1500.pdf fill_form '.$fdf_dir.$fdf_file.' output '.$fdf_dir.$pdf_file.' flatten');
exec('del '.$fdf_dir.$fdf_file);

 

 

I then make sure that my PDF form file, pdftk.exe and libiconv2.dll are in the same directory as the file calling these commands (which in my case is index.php in the root directory) and this works like a charm.  Where do you have your files located?

Link to comment
Share on other sites

Here's all I do:

 

$fdf_file="CMS".$focus->caseid.".fdf";
$pdf_file="CMS".$focus->caseid.".pdf";
$fdf_dir=".\\pdfFiles\\";
exec('pdftk cms1500.pdf fill_form '.$fdf_dir.$fdf_file.' output '.$fdf_dir.$pdf_file.' flatten');
exec('del '.$fdf_dir.$fdf_file);

 

 

I then make sure that my PDF form file, pdftk.exe and libiconv2.dll are in the same directory as the file calling these commands (which in my case is index.php in the root directory) and this works like a charm.  Where do you have your files located?

 

Okay, I've got everything in the same directory with the exception of the results directory.  I'm missing the pdftk.exe and libiconv2.dll.  That's probably what's wrong.  I have time this afternoon to work on this, so I'm going to give it a shot.  Thanks so much...  Hope it works!

Link to comment
Share on other sites

Yup.  That's probably it.  Here's the link:

 

http://www.pdflabs.com/docs/install-pdftk/

 

Still having some issues.  It may be related to my directories.  I'm not in the root.  I'm running everything from a directory called PDF.  Maybe I should just go to the root?

 

This is what it looks like:

 

        if($fp=fopen($fdf_dir.'/'.$fdf_file,'w')){

                fwrite($fp,$fdf_data,strlen($fdf_data));

                echo $fdf_file,' written successfully.';

            }else{

                die('Unable to create file: '.$fdf_dir.'/'.$fdf_file);

            }

$fdf_file="CMS".$focus->caseid.".fdf";

$pdf_file="CMS".$focus->caseid.".pdf";

$fdf_dir=".\\pdf\results\\";

exec('pdftk test.pdf fill_form '.$fdf_dir.$fdf_file.' output '.$fdf_dir.$pdf_file.' flatten');

exec('del '.$fdf_dir.$fdf_file);

            fclose($fp);

        }

    }else{

        echo 'You did not submit a form.';

    }

?>

Link to comment
Share on other sites

That's what I would recommend.  I tried doing something similar to what you have (pdf in one directory, pdftk.exe in another directory, file executing in another directory), and I kept getting errors.  Then I just dumped them all in the root, and it just worked.

 

But from your example, do you have the exe and dll files in the same directory as the file that's calling the exec() function, because that's how it looks pathed out?

Link to comment
Share on other sites

No sure.  But the FDF is writing and I have the permission set to write and execute.  Did you have to change anything in the createFDF.php file?

 

function createFDF($file,$info){

    $data="%FDF-1.2\n%âãÏÓ\n1 0 obj\n<< \n/FDF << /Fields [ ";

    foreach($info as $field => $val){

    if(is_array($val)){

        $data.=<</T('.$field.')/V[';

        foreach($val as $opt)

        $data.='('.trim($opt).')';

        $data.=]>>';

    }else{

        $data.='<</T('.$field.')/V('.trim($val).')>>';

    }

    }

    $data.="] \n/F (".$file.") /ID [ <".md5(time()).">\n] >>".

        " \n>> \nendobj\ntrailer\n".

        "<<\n/Root 1 0 R \n\n>>\n%%EOF\n";

    return $data;

}

Link to comment
Share on other sites

Nope.  Didn't change anything.  Although this is what my $date looks like in my file:

 

$data="%FDF-1.2\n%&#65533;&#65533;&#65533;&#65533;\n1 0 obj\n<< \n/FDF << /Fields [ ";

 

Hmmm..  I dunno.  If all your PHP, EXE, DLL and PDF form files are in the same directory and it's still not generating a PDF, then permissions is the only thing I can think of.  Hell, I even gave the "Everyone" group full permissions.  What web server are you using?

Link to comment
Share on other sites

  • 1 month later...

That's what I was thinking.  If everything is in the appropriate location, then the only explanation that I see is that your web server can't execute exe files or that the permissions aren't set to allow the execution of exe file.  You should be able to control that, right?  Do you have access to the server?

Link to comment
Share on other sites

  • 5 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.