Sunteți pe pagina 1din 14

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

Downloads
Documentation
Get Involved
Help

Search
Getting Started
Introduction
A simple tutorial
Language Reference
Basic syntax
Types
Variables
Constants
Expressions
Operators
Control Structures
Functions
Classes and Objects
Namespaces
Errors
Exceptions
Generators
References Explained
Predefined Variables
Predefined Exceptions
Predefined Interfaces and Classes
Context options and parameters
Supported Protocols and Wrappers
Security
Introduction
General considerations
Installed as CGI binary
Installed as an Apache module
Session Security
Filesystem Security
Database Security
Error Reporting
Using Register Globals
User Submitted Data
Magic Quotes
Hiding PHP
Keeping Current
Features

1 de 14

27/01/17 23:58

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

HTTP authentication with PHP


Cookies
Sessions
Dealing with XForms
Handling file uploads
Using remote files
Connection handling
Persistent Database Connections
Safe Mode
Command line usage
Garbage Collection
DTrace Dynamic Tracing
Function Reference
Affecting PHP's Behaviour
Audio Formats Manipulation
Authentication Services
Command Line Specific Extensions
Compression and Archive Extensions
Credit Card Processing
Cryptography Extensions
Database Extensions
Date and Time Related Extensions
File System Related Extensions
Human Language and Character Encoding Support
Image Processing and Generation
Mail Related Extensions
Mathematical Extensions
Non-Text MIME Output
Process Control Extensions
Other Basic Extensions
Other Services
Search Engine Extensions
Server Specific Extensions
Session Extensions
Text Processing
Variable and Type Related Extensions
Web Services
Windows Only Extensions
XML Manipulation
GUI Extensions
Keyboard Shortcuts
?
This help
j
Next menu item
k
Previous menu item
gp
Previous man page
2 de 14

27/01/17 23:58

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

gn
Next man page
G
Scroll to bottom
gg
Scroll to top
gh
Goto homepage
gs
Goto search
(current page)
/
Focus search box
fdf_add_doc_javascript
Ejemplos
Manual de PHP
Referencia de funciones
Salida MIME que no es texto
FDF
Change language: Spanish
Edit Report a Bug

Funciones de FDF
Tabla de contenidos
fdf_add_doc_javascript Aadir cdigo javascript al documento FDF
fdf_add_template Aadir una plantilla al documento FDF
fdf_close Cierra un documento FDF
fdf_create Crear un nuevo documento FDF
fdf_enum_values Invocar una funcin definida por el usuario por cada
dato del documento
fdf_errno Devuelve el cdigo de error de la ltima operacin sobre fdf
fdf_error Consultar la descripcin de un cdigo de error FDF
fdf_get_ap Consultar la publicacin de un campo
fdf_get_attachment Extraer un fichero subido por FDF
fdf_get_encoding Consultar el valor de la clave /Encoding
fdf_get_file Obtener el valor de la clave /F
fdf_get_flags Consultar banderas de un campo
fdf_get_opt Consultar un valor del array de opciones de un campo
fdf_get_status Obtener el valor de la clave /STATUS
fdf_get_value Obtener el valor de un campo
fdf_get_version Consulta el nmero de versin de la API o de un
fichero FDF
fdf_header Establecer cabeceras de salida especficas de FDF
3 de 14

27/01/17 23:58

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

fdf_next_field_name Obtener el siguiente nombre de campo


fdf_open_string Consulta un documento FDF a partir de un string
fdf_open Abrir un documento FDF
fdf_remove_item Asignar contenedor para el formulario
fdf_save_string Devuelve el documento FDF en forma de string
fdf_save Guardar un documento FDF
fdf_set_ap Establecer la apariencia de un campo
fdf_set_encoding Asignar codificacin de caracteres de FDF
fdf_set_file Establecer el documento PDF en donde desplegar datos
FDF
fdf_set_flags Establecer banderas de un campo
fdf_set_javascript_action Aadir una accin javascript a un campo
fdf_set_on_import_javascript Aadir cdigo javascript para ejecutar
cuando Acrobat abra el FDF
fdf_set_opt Establecer una opcin sobre un campo
fdf_set_status Establecer el valor de la clave /STATUS
fdf_set_submit_form_action Asignar accin a un campo de formulario
al enviarse
fdf_set_target_frame Definir contenedor en el que mostrar el
formulario
fdf_set_value Establecer el valor de un campo
fdf_set_version Asignar nmero de versin a un fichero FDF
add a note

User Contributed Notes 19 notes


up
down
3
Anonymous
11 years ago
Use "Yes" instead of "On" to populate checkboxes.

up
down
3
mitka at actdev.com
14 years ago
IMPORTANT:
If you handled the FDF POSTs via $HTTP_RAW_POST_DATA as in user contributed scripts
above, it's good to know that once you decide to rebuild PHP with FDFToolkit support,
$HTTP_RAW_POST_DATA will be undefined.
Good news - $HTTP_FDF_DATA _will_ be defined instead. (Look at the example above).To
get the user contributed scripts working in both plain PHP and PHP+FDFToolkit use
$HTTP_RAW_POST_DATA . $HTTP_FDF_DATA
where $HTTP_RAW_POST_DATA mentioned.

4 de 14

27/01/17 23:58

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

Dimitri Tarassenko

up
down
3
bea dot el dot tea at gmail dot com
5 years ago
If you can't get the php_fdf.dll working in PHP 5.3 on Windows, one possible work
around is to use the activeX version from the "FDF Toolkit for Windows" from the Adobe
website. Here is part of a class I built for one of my projects.
<?php
class FDF{
public $NormalAP = 0;
public $RolloverAP = 1;
public $DownAP = 2;
protected $fdf;
public function __construct(){
$com = new COM('FdfApp.FdfApp');
$this->fdf = $com->FDFCreate();
}
public function setFile($fileName){
$this->fdf->FDFSetFile(str_replace(' ', '%20', $fileName));
}
public function setValue($name, $value){
$this->fdf->FDFSetValue($name, $value, true);
}
public function setAP($field, $whichFace, $fileName, $pageNumber){
$this->fdf->FDFSetAP($field, $whichFace, $fileName, $pageNumber);
}
public function savetoFile($saveFileName){
$this->fdf->FDFSavetoFile($saveFileName);
}
public function close(){
$this->fdf->FDFclose();
}
}
?>

up
down
2
wesley_grant at yahoo dot com
11 years ago
Changing the
session.cache_limiter
directive in the php.ini file to 'private'

5 de 14

27/01/17 23:58

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

seems to resolve the issue with sending fdf data and session headers at the same time
to Internet Explorer.

up
down
2
fleischer at mail dot com
13 years ago
The code suggested by greg@... and adam@... is extremely helpful, but I've found out
(the hard way) that unclosed parentheses within strings contained in the input array
($values in greg's code or $pdf_data in adam's) will cause Acrobat to issue an error to
the effect that the file is corrupted. In other words, if there are strings such as "a)
my first point; b) my second point" in the input array, the resulting PDF/FDF file will
be considered corrupted by Acrobat. This apparently happens because all the field names
in the structure of an FDF file are enclosed in parentheses.
The solution I've devised is to escape all opening and closing parentheses with a
backslash, which in turn means you need to escape all backslashes. The code below does
all that.
Erik
--------------function output_fdf ($pdf_file, $pdf_data)
{
$fdf = "%FDF-1.2\n%\n";
$fdf .= "1 0 obj \n<< /FDF ";
$fdf .= "<< /Fields [\n";
$search = array('\\', '(', ')');
$replace = array('\\\\', '\(', '\)');
foreach ($pdf_data as $key => $val)
{
$clean_key = str_replace($search, $replace, $key);
$clean_val = str_replace($search, $replace, $val);
$fdf .= "<< /V ($clean_val)/T ($clean_key) >> \n";
}
$fdf .= "]\n/F ($pdf_file) >>";
$fdf .= ">>\nendobj\ntrailer\n<<\n";
$fdf .= "/Root 1 0 R \n\n>>\n";
$fdf .= "%%EOF";
return $fdf;
}

up
down
2
noah at NOSPAMbrandfidelity dot com

6 de 14

27/01/17 23:58

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

14 years ago
function parse($file) {
if (!preg_match_all("/<<\s*\/V([^>]*)>>/x",
$file,$out,PREG_SET_ORDER))
return;
for ($i=0;$i<count($out);$i++) {
$pattern = "<<.*/V\s*(.*)\s*/T\s*(.*)\s*>>";
$thing = $out[$i][1];
if (eregi($pattern,$out[$i][0],$regs)) {
$key = $regs[2];
$val = $regs[1];
$key = preg_replace("/^\s*\(/","",$key);
$key = preg_replace("/\)$/","",$key);
$key = preg_replace("/\\\/","",$key);
$val = preg_replace("/^\s*\(/","",$val);
$val = preg_replace("/\)$/","",$val);
$matches[$key] = $val;
}
}
return $matches;
}

up
down
1
Teemu
13 years ago
Maybe you have to use Header-function that your browser will regonize xfdf-file. Like
this:
Header( "Content-type: application/vnd.adobe.xfdf");

up
down
2
g8z at yahoo dot com
12 years ago
This is for users who are looking for a way to merge HTML form data with a PDF Form,
then output the PDF Form with data populated in it, to a web browser.
This is a pure PHP solution which does NOT require the FDF toolkit. Contributed by
www.TUFaT.com
<?php
// the full http path to the PDF form
$form = 'http://my_domain.com/my_pdf_form.pdf';
function create_fdf ($pdffile, $strings, $keys)
{
$fdf = "%FDF-1.2\n%\n";
$fdf .= "1 0 obj \n<< /FDF << /Fields [\n";

7 de 14

27/01/17 23:58

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

foreach ($strings as $key => $value)


{
$key = addcslashes($key, "\n\r\t\\()");
$value = addcslashes($value, "\n\r\t\\()");
$fdf .= "<< /T ($key) /V ($value) >> \n";
}
foreach ($keys as $key => $value)
{
$key = addcslashes($key, "\n\r\t\\()");
$fdf .= "<< /T ($key) /V /$value >> \n";
}
$fdf .= "]\n/F ($pdffile) >>";
$fdf .= ">>\nendobj\ntrailer\n<<\n";
$fdf .= "/Root 1 0 R \n\n>>\n";
$fdf .= "%%EOF";
return $fdf;
}
// Fill in text fields
$strings = array(
'date' => '10/17/2004',
'full_name' => 'Joe Doe',
'phone_num' => '123-4567',
'company' => 'ACME Widgets',
'amount' => 'USD 100.00'
);
// Fill in check boxes/radio buttons
$keys = array('
gender' => 'male',//radio button
'is_adult' => 'Off',//checkbox
'urgent' => 'On'//checkbox
);
// Output the PDF form, with form data filled-in
header('Content-type: application/vnd.fdf');
echo create_fdf($form, $strings, $keys);
?>

up
down
2
software at yvanrodrigues dot com
12 years ago
Do not use version 6 of the fdftk.dll (windows) with PHP4.3.4, use the one that comes
with PHP.

8 de 14

27/01/17 23:58

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

If you use the newer DLL fdf_create will not return a valid handle.

up
down
2
mirage at rateaprof dot com
13 years ago
If you get the new fdftkv5.tar.gz from adobe's site (per the link above), you'll get
some totally new spacing and capitalization of files. To make the current 4.3.1
configure, you need to do a few things.
untar fdftkv5.tar.gz into /usr/local
cd /usr/local
#for ease of use
ln -s FDFToolkit\ for\ UNIX fdf
cd fdf
ln -s Headers\ And\ Libraries HeadersAndLibraries
#may need to modify the following for your OS
ln -s LINUX linux
cd linux/C
ln -s LIBFDFTK.SO libfdftk.so
cd ..
cd ..
ln -s Headers headers
cd headers
ln -s FDFTK.H fdftk.h
And that should get you going... and to whoever is maintaining the configure script,
please be aware there are changes in the FDF Toolkit.

up
down
2
jeff at cowart dot net
14 years ago
I have tried to use the scripts above by adam and Toppi and I have been unable to get
them to work unless I save the generated fdf file and then open it manually in acrobat.

up
down
2
Toppi at i-Mehl dot De
14 years ago
I tried a lot with FDF -> PDF and merging these documents...
in my opinon xfdf is more handy than fdf... for those who'd like to try: feel free to
use this little function to generate an xfdf document from an array.
ToPPi
function array2xfdf($xfdf_data, $pdf_file) {

9 de 14

27/01/17 23:58

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

// 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;
}

up
down
1
bmount at livid dot us
11 years ago
For those of you struggling with FDF in Internet Explorer, here is your solution:
DO NOT INITIALIZE A SESSION ON THE PAGE THAT GENERATES AND OUTPUTS FDF DATA.
This will fix the page not found error.

up
down
1
m1tk4 at hotmail dot com
12 years ago
If you want to add FDF support without rebuilding your RedHat EL3 / Fedora PHP RPMs,
see instructions at http://phprpms.sourceforge.net/fdf

up
down
1
joe at koontz dot net
16 years ago
The simplest thing to do is get the FDF data from $HTTP_RAW_POST_DATA. (unless you
have the server library installed none of the fdf data gets parsed!) This is typical
of what you get:
%FDF-1.2
1 0 obj
<<
/FDF << /Fields [ << /V (0)/T (amount0)>> << /V (0)/T (amount1)>> << /V (0)/T
(amount2)>>
<< /V (0)/T (amount3)>> << /V (0)/T (amount4)>> << /V (0)/T (amount5)>>
<< /V (0)/T (amount6)>> << /V (0)/T (amount7)>> << /V (0)/T (amount8)>>
<< /V (0)/T (amount9)>> << /V /0102 /T (chase_bk)>> << /V (0)/T (count)>>

10 de 14

27/01/17 23:58

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

<< /V (0)/T (invtotal)>> << /V (12/21/2000)/T (sent_ap)>> << /V /Off /T (spec_hand)>>


<< /V (041232)/T (transit_no)>> << /V (THIS FORM IS NOT COMPLETE!!!)/T (X)>>
]
/F (http://x.com/forms/AA00390q.pdf)>>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%EOF
kill everything before the [ and then parse it down into key value pairs.
I wrote this to create an FDF, make sure you do a
header("Content-type: application/vnd.fdf");
before you echo the returned value to the user.
<?php
function FDFput($FDFpage){
$A = "%FDF-1.2\n1 0 obj\n<< \n/FDF << /Fields [ \n";
$C = " ] \n" ;
if ($FDFpage>"" ) {$C .=" /F ($FDFpage)>>\n";}
$C .= ">>\n>> \nendobj\ntrailer\n\n<</Root 1 0 R>>\n%%EOF\n";
$B = "";
reset($FDFData);
while (list($key, $val) = each($FDFData))
{
if (strlen(trim($val)) > 0 && is_string($key))
{
$B .= "<</T ($key) /V (". $val . ")>>\n";
//echo "<</T ($key) /V (". $val . ")>>\n";
}
}
return $A.$B.$C;
}
?>
It ain't perfect - but it works. (I use HTML for posting to the server, FDF to the
browser)
joe

up
down
0
sid at accesspdf dot com
12 years ago
Basic FDF data is easy to create using native PHP; you don't need Adobe's FDF Toolkit.
I wrote a function for this purpose called forge_fdf(). You can download it from:
http://www.pdfhacks.com/forge_fdf/

11 de 14

27/01/17 23:58

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

I created it for my book, PDF Hacks. An example of forge_fdf() in action can be viewed
online:
http://pdfhacks.com/form_session/form_session-1.1/
Download the full code for this online example from:
http://pdfhacks.com/form_session/
Note how the PDF form data is submitted back to the server via POST rather than FDF. No
need to parse FDF.
CheersSid Steward

up
down
0
adam at andemyte dot com
14 years ago
Here is yet another example of generating pre-filled PDFs without using the FDF
functions. This function takes two args: a URL to the PDF (like "http://domain.com
/path/to/form.pdf" and an array with all the field's values.
/*
WARNING!! THIS FUNCTION SENDS HTTP HEADERS! It MUST be called before
any content is spooled to the browser, or the function will fail!
void output_fdf (string $pdf_file, array $pdf_data)
$pdf_file: a string containing a URL path to a PDF file on the
server. This PDF MUST exist and contain fields with
the names referenced by $pdf_data for this function
to work.
$pdf_data: an array of any fields in $pdf_file that you want to
populate, of the form key=>val; where the field
name is the key, and the field's value is in val.
*/
function output_fdf ($pdf_file, $pdf_data) {
$fdf = "%FDF-1.2\n%\n";
$fdf .= "1 0 obj \n<< /FDF ";
$fdf .= "<< /Fields [\n";
foreach ($pdf_data as $key => $val)
$fdf .= "<< /V ($val)/T ($key) >> \n";
$fdf .= "]\n/F ($pdf_file) >>";

12 de 14

27/01/17 23:58

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

$fdf .= ">>\nendobj\ntrailer\n<<\n";
$fdf .= "/Root 1 0 R \n\n>>\n";
$fdf .= "%%EOF";
/* Now we display the FDF data which causes Acrobat to start */
header ("Content-Type: application/vnd.fdf");
print $fdf;
}

up
down
-1
gregDELETETHIS at laundrymat dot tv
15 years ago

13 de 14

27/01/17 23:58

PHP: Funciones de FDF - Manual

http://php.net/manual/es/ref.fdf.php

up
down
-2
info at theindigoworks dot com
9 years ago

add a note

FDF
Introduccin
Instalacin/Configuracin
Constantes predefinidas
Ejemplos
Funciones de FDF
Copyright 2001-2017 The PHP Group
My PHP.net
Contact
Other PHP.net sites
Mirror sites
Privacy policy

14 de 14

27/01/17 23:58

S-ar putea să vă placă și