Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using FDF to set a PDF field value 1

Status
Not open for further replies.

mtawk

Programmer
Nov 6, 2001
26
IQ
I have a PDF file in which there are a number of fields I wish to set them from PHP before opening the PDF file.
I tried many FDF examples i found on the web but nothing seems to be working.
Does anyone knows a simple example for how to set a value to a field in a PDF file dynamically from PHP.

Thanks for any help
 
I did some work with FDF some time ago and don't recall any trouble.
Have you tried this:
Code:
<?php
  /* set content type for Adobe FDF */
  fdf_header();

  /* start new fdf */
  $fdf = fdf_create();
    
  /* set field &quot;foo&quot; to value &quot;bar&quot; */
  $fdf_set_value($fdf, &quot;foo&quot;, &quot;bar&quot;);

  /* tell client to display FDF data using &quot;fdf_form.pdf&quot; */
  fdf_set_file($fdf, &quot;[URL unfurl="true"]http://www.example.com/fdf_form.pdf&quot;);[/URL]

  /* output fdf */
  fdf_save();

  /* clean up */
  fdf_close();
?>
 
Yes i have tried it but i'm always getting this message after the opening of Acrobat Reader :
&quot;There were an error in opening the document. File does not begin with '%PDF-'&quot;.

I have changed the PDF file and it is still giving me the same message. What may i have done wrong?
 
How did you create the fields in your PDF?
Do you have Acrobat?
 
Yes, i created it in Adobe Acrobat 4.
Is there anything special i should change in the properties of the field in the PDF file?
 
Not that I recall. The only difference when I used the FDF functions was that I used Acrobat 5.0 to create the interactive PDF.

Have you opened the form itself in the reader and tried to save an FDF file from the Reader itself?
 
No i haven't done that and I don't know how exactly i can do it.
Actually this is my first time working on Acrobat reader.

My problem is that i have a already done PDF report in which there is a number of fields that i must fill dynamically according to the client that is demanding the report. So i have nothing to change in the PDF report but the values of the fields.

In your opinion what is the best way to do so?

Thanks for your help
 
I believe your approach is the right thing to do.
I had a project where I had to fill out gouvernment forms and used the same approach very successfully.

I don't have access to the code right now but I could take a look tonite what I have done.
 
I would be very grateful because i didn't find any working example I can rely on.

Hope I'm not too much disturbing you.
 
Ok, I found some time to find the basi code.
This work fine for me using the Toolkit V5, PHP 4.3.2 and a PDF created in Acrobat 5.0
Code:
<?php
$outfdf = fdf_create();
fdf_set_value($outfdf, &quot;1a.insuredID&quot;, '123456789');
fdf_set_file($outfdf, &quot;[URL unfurl="true"]http://localhost/templates/HCFA1500.pdf&quot;);[/URL]
fdf_save($outfdf, &quot;c:/application/outtest.fdf&quot;);
fdf_close($outfdf);
Header(&quot;Content-type: application/vnd.fdf&quot;);
$fp = fopen(&quot;c:/application/outtest.fdf&quot;, &quot;r&quot;);
fpassthru($fp);
exit;
?>
Let me know what happens.
 
Thanks a lot, your code worked ok. I guess my mistake was that i'm not specifiying physically the address where the fdf must be created &quot;c:/application/outtest.fdf&quot;.

Your code works on windows OS, but my next challenge is compiling the php library with fdftk over Linux in order to be able to generate fdf files over Linux OS.

Do you have any idea how to do so?
 
sleipnir214 just had a full thread about how to compile PHP with options for Linux.
thread434-666901
I hope that thread will help you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top