FDF documentation support for PHP

Source: Internet
Author: User
Tags contains documentation fdf html form php script reference reset strlen
(reservation)
PHP has been for more than a year, from 3.0 to 4.0, can not say how high (I am now just a big rookie, compared to what, Hunte, much worse, of course, there are other masters), but also some experience. From the fiery PHP to the present calm, all the way to see more, listen to more, saw the "master" (will write message board, chat room, etc.) also more, quiet down a think: PHP is just a language. It has its own necessity of existence. The domestic web development also only stays in the low-level level, thought originally abroad in vigorously develops the ASP component, we only can use asp,php also. But thanks to PHP, it gave me a second job in my life (the first is ASP, at the beginning, I have never thought of it, but I know a lot of friends through it, Hunte, Chen Boss, a snake, He Zhiqiang (although there is no contact, but his article let me Benefit not), Sony, MACRO,CFR ... In order to make a living, for the future development, the niche will leave the PHP industry, although unwilling, but also helpless, will be dragged a long time an article translated as the last gift to everyone, dedicated to all the use of php&mysql friends. If there are learning VC and driver development friends can and
I contacted, let's discuss together.
---------------------------------------------------------------


Motivation

The interaction on www means filling in a form, clicking the Submit button, and then getting a definite result.  HTML and HTTP provide a mechanism to easily perform this action through a form. PHP supports this mechanism in a very convenient way, and the value of each input field (the form's input box) 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 acrobat form. From a user's standpoint, the only difference between an HTML form and an Acrobat form is their appearance. The former uses HTML documents, which use PDF documents to render the form.

To develop the Web interface, an 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 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 Acrobat forms. Using a PDF document as a form and generating a PDF document with data in PHP will be described in this article. You'll find out how easy these two examples are.

Before you start to try the online examples 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, 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.

In the past few years, Adobe has developed a Portable Document format (PDF) and expanded it. An extension is an Acrobat form that allows a user to enter data and process it in a server, just like an HTML form.
Such a PDF document is similar to a static PDF document, but when you look at it with an 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 entry fields, check boxes, and so on. Creating such a PDF form requires Acrobat Exchange 3.x or new Acrobat 4 software, which unfortunately 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 invoked when it is pressed. This is much like HTML, but the difference is in the format when data is delivered to the server.
When the submit button is pressed, the data is transmitted from the HTML form in a definite format that can be observed in the URL. Acrobat forms support This format, and FDF (form data format) The FDP is a new format that needs to be explained 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 fields by name. FDF data is commonly found in PHP's Http_raw_post_data variables (just as HTML data is stored in http_poat_data)
The actual assignment of the data is done in the PHP script, whereas the HTML submission data is assigned in the PHP engine.

To get a FDF data look, here is an example: the original document from the Internet so, I can not see what is garbled, but if you can see it in English system

%fdf-1.2% Repentance 1 0 obj <</fdf <</fields [<</V (this are 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 field (may be the title bar) and its value. Here is the test text.

This makes it clearer and provides a simple example.  First, suppose we have a PDF form that contains a number of publishers, a publisher, a date, a note issuer, a release preparation, and so on. The first five fields are text fields, and the last two fields are check boxes. Our PHP script always displays the number, date, and value of the annotation field, and the value of the Publisher and the Prep field is displayed when the corresponding check box is selected.
If this box (check box) is selected, their value is "on", which is set when the form is created. Of course this form also has a submit button, and in our case it 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.

<?php

$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 ' <B> $volume </B> ' <BR> ';

$date = Fdf_get_value ($FDF, "date");
echo "The Date field has the value ' <B> $date </B> ' <BR> ';

$comment = Fdf_get_value ($fdf, "comment");
echo "The comment field has the value ' <B> $comment </B> ' <BR> ';

if (Fdf_get_value ($FDF, "show_publisher") = = "On") {
$publisher = Fdf_get_value ($fdf, publisher);
echo "The Publisher field has the value ' <B> $publisher </B> ' <BR> ';
} else
echo "Publisher shall not to be shown.<br>";

if (Fdf_get_value ($FDF, "show_preparer") = = "On") {
$preparer = Fdf_get_value ($FDF, "preparer");
echo "The Preparer field has the value ' <B> $preparer </B> ' <BR> ';
} else
echo "preparer shall not to be shown.<br>";
Fdf_close ($FDF);

?>

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



More realistically, PDF forms have a better look than HTML forms, and this technique seems to have no definite advantage. However, PDFs have another use. You can review the above
Process and make a PDF document with the data.
If you need to customize a PDF document only a few of the identified parts, such as address, date and so on. It can also be used to create a complete PDF document, but to create a mixed document with PHP's PDF document feature
It takes a lot of work.
For example, in general, it is also worthwhile for designers to create prepared documents (may be drafts). It is almost impossible to create a PDF form with the PDF document feature in PHP (not FDF document).

It's easy to make a PDF document with data in FDF. If you use Acrobat 4, you will have to create a PDF document and add the input fields to it.  On your Web server. Then you need to create a FDF document with PHP, which contains references to each field, its value and the data that will be inserted into the document. (This PDF document you've just built). This will be handled very quickly in PHP. A reference to a document is a URL that points 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.

<?php

$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 are performed:
In this example, several steps have been completed:

The user has clay the PDF form Example2.pdf
After clicking the Submit button, the URL associated with the submit button has been invoked. In this example, the PHP script has been executed. The PHP script retrieves the data from the FDF data stream and creates a new FDF document
It contains data for the PDF document as a result.

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

The Acrobat plugin reads the data and displays the reference PDF document. In this case, the 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 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.