FDF Documentation Support for PHP

Source: Internet
Author: User
Tags fdf fdf file
Author: UweSteinmann Source: www.phpbuilder.com translator, compared with Ho and Hunte, it is much worse. Of course there are other experts), but there are also some experiences. Fire from PHP author: Uwe Steinmann
Source: http://www.phpbuilder.com
Znsoft webmaster@phpease.com http://www.phpease.com

Note: (retain)
I have been using PHP for more than a year. from 3.0 to 4.0, I can't say how high it is. (I am also a newbie. it's much worse than he and Hunte. Of course there are other masters ), but there are also some experiences. From the popularity of PHP to the calm of the present, there have been more views and more listening, and there have been many "Masters" (who can write message boards, chat rooms, and so on). let's calm down and think: PHP is just a language. It has its own necessity. Web development in China is only at a low level. I think we will only use asp when developing asp components abroad, and PHP will be the same. But thanks to php, it gave me a second job in my life (the first job is asp. I didn't think of c/c ++ at the beginning ), of course, I have also known many friends through it, Hunte, Chen boss, a snake, He Zhiqiang (although I have not been in touch, but his articles have benefited me), sony, macro, cfr... for the sake of livelihood and for the future development, Xiaosheng will leave the PHP field, though unwilling, but helpless, and will translate an article that has been dragged on for a long time as the last gift to everyone, to all friends who use PHP and mysql. If you want to learn about VC and driver development, you can
Let's discuss it together.
---------------------------------------------------------------


Motivation

The interaction on WWW means to fill in the table, click the submit button, and then get a definite result. Html and Http provide a mechanism to easily execute such operations through forms. PHP supports this mechanism in a very convenient way. The value of each input field (the input box of the form) is stored as a PHP variable with the same name as the input field.

A similar mechanism has been developed by adobe, but it is for PDF documents. They simply call it the Acrobat form. From the user's point of view, the only difference between Html forms and Acrobat tables is their appearance. The former uses HTML documents, and the latter uses PDF documents to render forms.

To develop a WEB interface, the Acrobat form can also be processed like an HTML form, if the form provides input data like an HTML form. However, Adobe has proposed a new format for form data, namely FDF (form data format ). PHP already supports this format.

The possibility of generating a PDF document with data, such as customizing it, is an additional feature of the Acrobat form. PDF documents are described in this article. You will find out how easy these two examples are.

Install the Acrobat Reader plug-in or use Acrobat 4. if you want to test the php script on your web server, you also need to install the PDF toolkit and make the FDF support in PHP take effect.

Finally, if you develop your own PDF form, you need Acrobat Exchange 3.x or Acrobat 4.

In the past few years, Adobe has developed and extended portable document formats (PDF. An extension is an Acrobat form that allows users to input data and send it to the server for processing, just like an HTML form.
Such a PDF file is similar to a static PDF file, but when you use Acrobat reader to view it, you will find an editable area. As in HTML, many input fields are valid, such as The submit and reset buttons, text input fields, check boxes, and so on .. to create such a PDF form, Acrobat Exchange 3 is required. x or the new Acrobat 4 software, unfortunately they can only run in windows and MacOS.
Both provide a way to place different input fields in an existing PDF file.
The submit button transmits the URL attribute called when it is pressed. This is very similar to HTML, but the difference is the format when data is transmitted to the server.
When you press the Submit button, the data is transmitted from the HTML form in a fixed format that can be observed in the URL. Acrobat forms support this format, and FDF (form data format) FDP is a new format that needs to be explained by the FDF Toolkit (current version 4.0. If PHP supports FDF during compilation, it can parse FDF Data and access any input domain by name. FDF Data is usually stored in the HTTP_RAW_POST_DATA variable of PHP (just as HTML data is stored in HTTP_POAT_DATA)
The actual data assignment is completed in the PHP script. On the contrary, the HTML submitted data is assigned a value in the PHP engine.

To get a FDF Data look like this, here is an example, but you can check it in the English system)

% FDF-1.2 % empty too 1 0 obj </FDF </Fields [</V (This is just some text for testing) /T (comment)> ....

This is only the first part of a complete record, but it can clearly indicate the annotation of the input domain (which may be the title) and its value. Here is the test text.

This makes it clearer and provides a simple example. First, assume that we have a PDF form that contains fields such as the number, publisher, prepared by, date, annotation issuer, and issuer. The first five fields are text fields, and the last two fields are check boxes ). Our PHP scripts always display the quantity, date, and annotation field values. when the corresponding check box is selected, the values of the publisher and prepared domain are displayed.
If this box is selected, its value is "On", which is set when the form is created. Of course, this form also has a submit button. In our example, it even has a reset button.
Click submit to run the following script. This script assigns the value of the domain data as described above.


$ Fdffp = fopen ("test. fdf", "w ");
Fwrite ($ fdffp, $ HTTP_RAW_POST_DATA, strlen ($ HTTP_RAW_POST_DATA ));
Fclose ($ fdffp );

$ Fdf = fdf_open ("test. fdf ");
$ Volume = fdf_get_value ($ fdf, "volume ");
Echo "The volume field has the value' $ Volume'
";

$ Date = fdf_get_value ($ fdf, "date ");
Echo "The date field has the value' $ Date'
";

$ Comment = fdf_get_value ($ fdf, "comment ");
Echo "The comment field has the value' $ Comment'
";

If (fdf_get_value ($ fdf, "show_publisher") = "On "){
$ Publisher = fdf_get_value ($ fdf, "publisher ");
Echo "The publisher field has the value' $ Publisher'
";
} Else
Echo "Publisher shall not be shown.
";

If (fdf_get_value ($ fdf, "show_preparer") = "On "){
$ Preparer = fdf_get_value ($ fdf, "preparer ");
Echo "The preparer field has the value' $ Preparer'
";
} Else
Echo "Preparer shall not be shown.
";
Fdf_close ($ fdf );

?>

You can try this example http://gehtnix.fernuni-hagen.de: 8000/testfdf/example1.pdf



Compared with the actual situation, PDF forms have a better appearance than HTML forms. this technology does not seem to have a definite advantage. However, PDF is another useful method. You can review the above
Process, and use data to form a PDF document.
If you need to customize only a few definite parts of the PDF document, such as the address and date. It can also be used to create a complete PDF document, but to create a hybrid document using the pdf document function of PHP
A lot of work is required.
For example, in general, it is also worthwhile for designers to create preparation documents ). Using the PDF document function in PHP to create a PDF form is almost impossible.

It is easy to use data to form a PDF document in FDF. If you use Acrobat 4, you must create a PDF document and add it to the input field. Put it on your web server. Then, you need to use PHP to create the FDF document, which contains the reference of each domain, its value and data to be inserted in the document. (You have already created this PDF file ). This will be quickly processed in php. The document reference is a URL pointing to a PDF document.

Based on the first example, the following php script is very easy. The second part of the script has been added.


$ Fdffp = fopen ("test. fdf", "w ");
Fwrite ($ fdffp, $ HTTP_RAW_POST_DATA, strlen ($ HTTP_RAW_POST_DATA ));
Fclose ($ fdffp );

$ Fdf = fdf_open ("test. fdf ");
$ Volume = fdf_get_value ($ fdf, "volume ");
$ Date = fdf_get_value ($ fdf, "date ");
$ Comment = fdf_get_value ($ fdf, "comment ");

If (fdf_get_value ($ fdf, "show_publisher") = "On "){
$ Publisher = fdf_get_value ($ fdf, "publisher ");
} Else
$ Publisher = "";

If (fdf_get_value ($ fdf, "show_preparer") = "On "){
$ Preparer = fdf_get_value ($ fdf, "preparer ");
} Else
$ Preparer = "";

Fdf_close ($ fdf );

$ Outfdf = fdf_create ();
Fdf_set_value ($ outfdf, "f_volume", $ volume, 0 );
Fdf_set_value ($ outfdf, "B _volume", $ volume, 0 );

Fdf_set_value ($ outfdf, "f_comment", $ comment, 0 );
Fdf_set_value ($ outfdf, "B _comment", $ comment, 0 );

Fdf_set_value ($ outfdf, "f_date", $ date, 0 );
Fdf_set_value ($ outfdf, "B _date", $ date, 0 );

Fdf_set_value ($ outfdf, "f_preparer", $ preparer, 0 );
Fdf_set_value ($ outfdf, "B _preparer", $ preparer, 0 );

Fdf_set_value ($ outfdf, "f_publisher", $ publisher, 0 );
Fdf_set_value ($ outfdf, "B _publisher", $ publisher, 0 );

Fdf_set_file ($ outfdf, "http:/testfdf/resultlabelease ");
Fdf_save ($ outfdf, "outtest. fdf ");
Fdf_close ($ outfdf );
Header ("Content-type: application/vnd. fdf ");
$ Fp = fopen ("outtest. fdf", "r ");
Fpassthru ($ fp );
Unlink ("outtest. fdf ");

?>

You can also try this example http://gehtnix.fernuni-hagen.de: 8000/testfdf/example2.pdf

In this example several steps are saved Med:
In this example, several steps have been completed:

The user has completed the PDF form example2.pdf
After you click the submit button, the URL associated with the submit button has been called. In this example, the PHP script has been executed. The PHP script retrieves data from the FDF Data stream and creates a new FDF document.
It contains the data of the PDF document as the result.

The FDF file is sent back using the application/vnd. fdf type.

The Acrobat plug-in reads data and displays the reference PDF document. In this example, it is resultlabelease.

This is still not everything that FDF does. There are many issues to be discussed in this tutorial.
You can check this document on adobe's web site.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.