Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Dynamic Fill in PDF Files

Avatar

Former Community Member
Hello,



i have a PHP Site where a user can type his personal data. When he click on the Button "Send", a PDF form open and fill the data into the form. The static PDF works with FDF, but the dynamic PDF with XFDF doesn´t work. Here my XFDF:



<?php



$pdf_file= 'http://localhost/Kunde2.pdf';



function array2xfdf($xfdf_data, $pdf_file)

{

// Creates an XFDF File from a 2 dimensional

// Array Format: "array ("key1" => "content1", "key2" => "content2");



$xfdf = "<?xml version='1.0' encoding='UTF-8'?>\n";

$xfdf .= "<xfdf xmlns='http://ns.adobe.com/xfdf/' xml:space='preserve'>\n";

$xfdf .= "<fields>\n";



// Loop -> Array to XFDF Data



foreach ($xfdf_data as $key => $val)

{

$xfdf .= "<field name='".$key."'>\n";

$xfdf .= "<value>".$val."</value>\n";

$xfdf .= "</field>\n";

}



// XFDF "Footer"

$xfdf .= "</fields>";

$xfdf .= "<f href='".$pdf_file."'/>";

$xfdf .= "</xfdf>";



return $xfdf;

}



$xfdf_data = array(

"KUNDE"=> $_POST['KUNDE'],



);



header('Content-type: application/vnd.adobe.xfdf');

echo array2xfdf($xfdf_data, $pdf_file);



?>



The Script open my PDF but without my data. What´s wrong? The XML Structur is ok. I work with the LiveCycle Designer 8. Must I change in the Designer any configuration?



greetings



Daniela
10 Replies

Avatar

Former Community Member
I am curious about this, too. I have an adobe pdf that I would like to have dynamically filled by data from a datatbase. The info is entered in through another program, and I'd like the info to basically be printed into each line of the pdf form.

Avatar

Former Community Member
I have a vital form that clients fill out, which is passed to many people in the company along the workflow. The form is a Planner and we have in the following PDF, Word Doc..



Well before, the Planner.pdf was originally created in Word, since most people have access to Word.. but evolved to a PDF form created from the Word Doc via Adobe LiveCycle Designer 8.0 w/ User Rights enabled so that the form could be filled out and saved using Adobe Reader.. which was a step better than Word.. being that it is free. But this needed to be easier and more to the point b/c some clients don't particularly like installing the latest version of Reader, even if you provide them the link. Nor do they like saving the form, filling the form, and attaching the form to send back.



My goal is to have the client fill an HTML version of the form, submit and be done with it, but everyone in the workflow be able to easily receive the filled Planner as a PDF form.



So some months ago I ran into this post Chris Trip, "Populate Livecycle PDF from mySQL database using PHP" #8, 22 Sep 2007 4:37 pm



which uses the command line Win32 pdftk.exe to merge an FDF file into an existing PDF on the remote server, and serve this to whoever.



My problem was with shared hosting and having the ability to use the Win32 pdftk.exe along with PHP which is predominantly used on Linux boxes. And we used a Linux box.



so i created the following unorthodox method, which a client fills the HTML version of the Planner, all field values are INSERTED into a table in MySQL DB, I and all filled planners that have been filled by clients to date can be viewed from a repository page where an XML file is served up of the corresponding client, but someone would have to have Acrobat Professional, to import the form data from the XML file into a blank form.. altoughh this is simple for me.. I have the PHP file already created so that when a Planner is filled and client submits. >> the an email is sent to me with a table row from the repository of the client name, #, email, and a link to d-load the XML file,



But I also have the PHP files created so that the Planner can be sent to by email to various people in the workflow with certain fileds ommitted they they do not need to see, but instead of the XML file beiong served up i need the filled PDF Planner to be served.



I can do this locally with ease on a testing server, but I am currently trying to use another host that uses cross-platform compatibility so i can use PHP and the pdftk.exe to achieve this, as that is why I am having to serve up an XML file b/c we use a Linux server for our website, and cant execute the exe.



Now that I am testing the other server (cross-platform host), just to use them to do the PDF handling (and it's only $5 per month) I am having problems with getting READ, WRITE, EXECUTE permissions..



Si guess a good question to ask is can PHP do the same procedure as the pdftk.exe, and i can eleminate it.



or how in the heck can i get this data from the DB into a blank PDF form, like i have described??



here are some link to reference



Populating a LiveCycle PDF with PHP and MySQL

http://www.andrewheiss.com/Tutorials?page=LiveCycle_PDFs_and_MySQL



HTML form that passed data into a PDF

http://www.mactech.com/articles/mactech/Vol.20/20.11/FillOnlinePDFFormsUsingHTML/index.html

and an example

http://accesspdf.com/html_pdf_form/

Avatar

Former Community Member
Hello,



I have got successes for inserting data that are submitted from pdf form. I am unable to populate that data in pdf form. During the time of opening pdf file it shows the message "the file corrupted or damaged".

I have used the same code of http://www.andrewheiss.com/Tutorials?page=LiveCycle_PDFs_and_MySQL.



Code is working properly and LoanAgreement.pdf form is filled with data. When I used my own form for filling data It shows the above message i.e file is corrupted or damaged.



Please help me for solving this problem. I have spent couple of days for solving this problem But I did not find out any solution.



Thank You

saroj neupane

Avatar

Former Community Member
Hey saroj,



If you are running onder windows make sure that the cmd.exe has read and write right for IUSR account

Avatar

Former Community Member
Hi Saroj,

I've had the error about the file being damaged or corrupted. This happened when i tried to remove the flatten switch from the pdftk command in viewpdf.php in Adrew Heiss's tutorial.

This is the original command:



passthru( 'pdftk LoanAgreement.pdf fill_form '. $fdf_fn.

' output - flatten' );



I found that to remove the flatten option i needed to use the following:

passthru( 'pdftk LoanAgreement.pdf fill_form '. $fdf_fn.

' output -' );



Hope this helps.



Having said all that. When i generate an interactive form on the server using this method, none of the interactive fields are filled with any data (they are when i use the flatten command).



Is this correct? I was hoping that some of the interactive fields would be prefilled with data generated from the database and i would be free to fill and save the remaining fields.



Is anyone else trying to do the same thing?

Avatar

Former Community Member
I create a fdf file with the same names in the html and pdf template and my fields are empty

Avatar

Former Community Member
I'm making a PDF in Acrobat Writer putting text data fields. When I open the PDF in Reader and insert data, after saving the copy of this PDF when open this copy in reader, no data is shown which I just entered.

Can anyone help me in resolving this problem?

Avatar

Former Community Member
I seem to have gotten all of it to work but I get the corrupt file message when I attempt to open the filled pdf in acrobat. My php log is clear so I dont have any other error messages to go on. I have searched and searched for a solution but I cannot find one.

Avatar

Former Community Member
I too am getting an error message. i've uploaded the files from the sample (http://www.accesspdf.com/html_pdf_form/) directly onto my website and did not change anything.... i tried to fill out the html form and when i hit submit, i get asked to "save" or "open" the pdf... the pdf says that the file cannot be opened. that it is corupt.



if i can't get the sample to work.. i don't know how to get my own forms to work.



any help would be greatly appreciated.



thanks in advance.

Avatar

Former Community Member
I am having the same error, all my information gets submitted to my mySQL database, but when I try to view the re-populated PDF, Reader says that the file is corrupted.