CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 [SOLVED] PDF Form Filling Output

Print topic Send  topic

Author Message
chriscripps

Posts: 30
Posted: 08/03/2008, 4:06 AM

Hi,
I hope that someone can help me "fix" my project. I have it working about perfectly on my local connection (using Firefox anyways, but not IE), but when I put it on the server, it does not work right.

What I am doing is filling in a form and then in the after insert event, develop text for an fdf file, save it to a new file with name based on the last insert id and then show the pdf with the filled in information to the user.

On the local machine, when I click Add button in my record builder form, it submits the info to the database (mysql), makes the string, writes the file, and then sends the string to the browser with a header and makes it open the program to read the pdf and shows the fields filled in. From here, the user can print the pdf filled in (what we need to do since the lab that this is going to does not have any online way of transmitting data). This is what I want it to do. One little problem here is that the page does not go to the return page, it stays on the filled in form.

On the server, when I click Add, it send the info to the database, it makes the file, and then returns to the return page, not the form. It does nothing to print the form or show the form to the user.

The after insert event is this:
//Get the inserted accession number and build a file name of the number.fdf and
//open the file for writing
$id = mysql_insert_id();
$filename = $id.".fdf";
$FileHandle = fopen($filename,'w') or die ("Can't open file");

//Build the FDF file string

//string start for server
//$data = "%FDF-1.2\n %âãÏÓ\n 1 0 obj \n<</FDF \n<</F(http://www.healthycows.com/diaglab.pdf) \n/Fields [";

//string start for local machine
$data = "%FDF-1.2\n %âãÏÓ\n 1 0 obj \n<</FDF \n<</F(/C/public_html/www/lab/diaglab.pdf) \n/Fields [";

$data= $data."<</T(Animal Name - 1) /V(".$Container->Animal_1_Name->Getvalue().")>>";
$data= $data."<</T(Animal Species - 1) /V(".$Container->Animal_1_Species->Getvalue().")>>";
$data= $data."<</T(Animal Breed - 1) /V(".$Container->Animal_1_Breed->Getvalue().")>>";

$data=$data."]>>>>endobj \ntrailer \n<</Root 1 0 R>> \n%%EOF";

//write the data string to the file and close the file
fwrite($FileHandle,$data);
fclose($FileHandle);

//output the file string so the browser opens the pdf file with the forms filled in
header ("Content-Type: application/vnd.fdf");
print $data;

In this code, I change which starting string is commented out depending on where it is going, local or server.

Can anyone help me figure how to get the filled in pdf to show from the server?

Thanks,
Chris
View profile  Send private message
chriscripps

Posts: 30
Posted: 08/03/2008, 4:14 AM

One thing I did to try to elaborate on this more is I set up another page with an editable grid and an accession number (key) changed to a link. The link points to another page (accessionIndividual) that is blank, but has a before show event that opens the appropriate file and sends it with a header to tell the browser it is a pdf to open :

//Get Accession number from URL parameter from refering page
$b = ccgetfromget("accession","");
//Make file name
$filename = $b.".fdf";
//Open the file and read the first 5000 characters and then close the file
$fh = fopen($filename, 'r');
$theData = fread($fh,5000);
fclose($fh);
//Send the file contents to the browser to open a new page with the pdf filled in
header ("Content-Type: application/vnd.fdf");
print $theData;

On the local server, clicking on the link will open my pdf program and show the form all filled in.

On the webserver, it will open the pdf without any information in it in a browser window. If I change the pdf name in the fdf file (purposefully make it wrong), it will say it cannot find the pdf and ask me to locate it. If I locate the local copy, it will show it to me all filled in in the pdf reader program outside of the browser.

Any thoughts on why this is doing this?

Thanks,
Chris
View profile  Send private message
datadoit
Posted: 08/03/2008, 7:50 AM

Perhaps the webserver doesn't know how to handle an .fdf file
(mimetype). Try giving it a .pdf extension instead.
chriscripps

Posts: 30
Posted: 08/03/2008, 8:14 AM

I tried that and it did not work. Once I did that, it said file not found and asked me to find the file and then opened the local copy of the pdf.
Thanks for thinking about it.
Chris
View profile  Send private message
DonP
Posted: 08/03/2008, 10:18 AM

As I recall, the PDF library is not installed by default so possibly it
is not on the live server.

Don (DonP)
chriscripps

Posts: 30
Posted: 08/03/2008, 1:25 PM

Don,
Can you elaborate on that? Is that something I should be installing or that my ISP should be installing? I am not really creating a pdf file with any of this code, just sending the form data to the pdf, so did not think I needed something like fpdf.
Thanks,
Chris
View profile  Send private message
datadoit
Posted: 08/03/2008, 7:01 PM

Okay, I see what you're doing... You're really using Acrobat to create
the PDF from FDF data on your local machine. The problem is your
webserver doesn't have Acrobat (or more literally the appropriate
dll's). You could probably get away with keeping your same design
concept on an IIS Windows hosted machine using the ActiveX component for
Acrobat (?).

Have a look at FPDI
(http://www.setasign.de/products/pdf-php-solutions/fpdi/). It'll allow
you to load pre-existing PDF documents, then overlay them with your data.
chriscripps

Posts: 30
Posted: 08/06/2008, 5:35 AM

datadoit,
Thanks, FPDI is what I will be using for this project. I originally thought this is what I would need to do, but then came up with the fdf stuff and thought that would be easier. I have the project figured out, now just need to write it out. A lot more work to get positioning and field sizes correct, but good control and consistent output of the project. I just wrote a positioning page to help show XY coordinates to help get things setup.
thanks,
Chris
View profile  Send private message
wkempees


Posts: 1679
Posted: 08/06/2008, 6:43 AM

Chris,
Could you change title to [SOLVED] and possibly more descriptive title as to PDF Form filling.
Would appreciate it.
Good discussion too.
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.