PHP's FDF document support _php

Source: Internet
Author: User
Keywords Support documentation forms PDF data PHP one
Tags fdf
Author: Uwe Steinmann
Source: http://www.phpbuilder.com
Translator: Znsoft webmaster@phpease.com http://www.phpease.com

(reserved)
PHP has been for more than a year, from 3.0 to 4.0, can not say how high (I am now just big rookie, compared to what, Hunte, much worse, of course, there are other masters), but also some experience. From the heat of PHP to the present calm, all the way to see more, listen to more, see the "Master" (will write message board, chat room, etc.) also more, calm down a think: PHP is just a language. It has its own necessity to exist. The domestic web development also only stays in the low level, thought originally abroad in vigorously develops the ASP component when we can only use asp,php also. But thanks to PHP, it let me get the life of the second job (the first is ASP, the original hard to learn C + +, how did not think of it), of course, also through it know a lot of friends, Hunte, Chen Boss, a snake, he Zhiqiang (although no contact, but his article let me benefit Non), Sony, MACRO,CFR ... In order to make a living, for the future development, niche will leave the PHP world, although reluctant, but also helpless, will drag a long time of an article translated as a final gift for everyone, dedicated to all use Php&mysql friends. If you have to learn VC and drive the development of friends can and
I contacted, let's explore together.
---------------------------------------------------------------


Motivation

The interaction on www means filling out a form, clicking the Submit button, and then getting a definite result. HTML and HTTP provide a mechanism to easily perform this operation through forms. PHP supports this mechanism in a very convenient way, and 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 very similar mechanism has been developed by Adobe, but it is a PDF document. They simply call it the Acrobat form. From a user's point of view, the only difference between an HTML form and an Acrobat form is their appearance. The former uses HTML documents, which use PDF documents to present the form.

To develop a web interface, Acrobat forms can also be processed like an HTML form, if the form provides input data as an HTML form. However, Adobe has presented a new format for form data called FDF (Form data format). PHP already contains support for this format.

The possibility of generating a PDF document with data, such as customizing it, is an additional feature of the Acrobat form. A PDF document is used as a form and a PDF document generated in PHP is described in this article. You'll find out how easy these two examples are.

Before you start trying the online example in this article, you will install the Acrobat Reader plugin or use Acrobat 4. If you want to test your PHP script on your Web server, you will also install the PDF Toolkit and make the FDF support in PHP effective.

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

Over the past few years, Adobe has developed a Portable Document format (PDF) and expanded it. An extension is an Acrobat form that allows the user to enter data and send it to the server for processing, like an HTML form.
Such a PDF document is similar to a static PDF document, but when you look at it with the Acrobat Reader, you will find editable regions. As in HTML, there are many input fields that are valid, such as Submit and reset buttons, text input fields, check boxes, and so on. Creating such a PDF form requires Acrobat Exchange 3.x or the new Acrobat 4 software, but unfortunately they can only run in Windows and MacOS.
Both provide a way to place different input fields into an existing PDF document.
The submit button transmits the URL property that is called when it is pressed. This is very much like HTML, but the difference is in the format when the data is delivered to the server.
When the submit button is pressed, the data is transferred from the HTML form in a deterministic format that can be observed in the URL. Acrobat forms support This format, and the FDF (form data format) FDP is a new format that needs to be interpreted by the FDF Toolkit (current version 4.0). If PHP adds FDF support at compile time, it can parse the FDF data and access any input domain by name. FDF data is typically present in PHP's Http_raw_post_data variable (just as HTML data is stored in http_poat_data)
The actual assignment of the data is done in a PHP script, whereas the HTML commit data is assigned in the PHP engine.

To get the look of an FDF data, here is an example: the original file from the online copy, I can not see the garbled is what, but if put in the English system to see it.

%fdf-1.2% Repentance 1 0 obj <</fdf <</fields [<</V (this was just some text for testing)/T (comment) >> ....

This is only the first part of a complete record, but it can clearly represent the input field annotations (probably the title bar) and its value. Here is the test text.

This makes it clearer and provides a simple example. First, let's say we have a PDF form that contains the number, publisher, the creator, the date, the note issuer, and the release preparation. The first five fields are text fields, and the last two fields are check boxes. Our PHP script always displays the value of the number, date, and annotation fields, and displays the values of the publisher and the Creator field when the corresponding check box is selected.
If the box (check box) is selected, their value is "on" which is set when the form is created. Of course this form also has the Submit button, which in our case even has the reset button.
Click the Submit button to run the following script. This script assigns the value of the field 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 being 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 being shown.
";
Fdf_close ($FDF);

?>

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



Compared to the actual situation, PDF forms have a better appearance than HTML forms, and this technique seems to have no definite advantage. However, PDFs have another use. You can review the above
Process and use the data to form a PDF document.
If you need to customize only a few definite parts of the PDF document, such as addresses, dates, and so on. It can also be used to create a complete PDF document, but to create a hybrid document with PHP's PDF document functionality
Need a lot of work.
In general, for example, it is also worthwhile for designers to create prepared documents (probably drafts). It is almost impossible to create a PDF form using the PDF document feature in PHP (not an FDF document).

It's easy to compose a PDF document with data in an FDF. When you use Acrobat 4, you will have to create a PDF document and add the input fields to it. Put it on your Web server. Then, you need to create the FDF document in PHP, which contains a reference to each field, its value and the document that the data will be inserted into. (This PDF document you have just built). This will be handled very quickly in PHP. A reference to a document is a URL 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/resultlabel.pdf");
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 is performed:
In this example, several steps have been completed:

The user has finished clay PDF form Example2.pdf
When the Submit button is clicked, the URL associated with the submit button has been called. In this example, the PHP script has been executed. PHP script retrieves data from the FDF data stream and creates a new FDF document
It contains the data as a result of the PDF document.

The FDF document is sent back with the APPLICATION/VND.FDF type.

The Acrobat plugin reads the data and displays this reference PDF document. In this case, it is resultlabel.pdf.

This is still not everything that FDF does, and there are a lot of things left to discuss in this tutorial.
You can verify this document on Adobe's Web site.
  • 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.