FDF 関数
目次
- fdf_add_doc_javascript — FDF ドキュメントに javascript コードを追加する
- fdf_add_template — テンプレートを FDF ドキュメントに追加する
- fdf_close — FDF ドキュメントを閉じる
- fdf_create — 新規 FDF ドキュメントを作成する
- fdf_enum_values — 各ドキュメントの値に対してユーザー定義関数をコールする
- fdf_errno — 直近の fdf 操作に関するエラーコードを返す
- fdf_error — 直近の fdf エラーコードについての説明を返す
- fdf_get_ap — フィールドの外観を取得する
- fdf_get_attachment — FDF に埋め込まれている、アップロードされたファイルを展開する
- fdf_get_encoding — /Encoding キーの値を取得する
- fdf_get_file — /F キーの値を得る
- fdf_get_flags — フィールドのフラグを取得する
- fdf_get_opt — フィールドのオプション配列から値を取得する
- fdf_get_status — /STATUS キーの値を得る
- fdf_get_value — フィールドの値を得る
- fdf_get_version — FDF API あるいはファイルのバージョンを取得する
- fdf_header — FDF 固有の出力ヘッダをセットする
- fdf_next_field_name — 次のフィールド名を得る
- fdf_open — FDF ドキュメントをオープンする
- fdf_open_string — 文字列から FDF ドキュメントを読み込む
- fdf_remove_item — フォームのターゲットフレームを設定する
- fdf_save — FDF ドキュメントを保存する
- fdf_save_string — FDF ドキュメントを文字列として返す
- fdf_set_ap — フィールドの外観を設定する
- fdf_set_encoding — FDF 文字エンコーディングを設定する
- fdf_set_file — FDF データを表示する PDF ドキュメントを設定する
- fdf_set_flags — フィールドのフラグを設定する
- fdf_set_javascript_action — フィールドの javascript アクションを設定する
- fdf_set_on_import_javascript — Acrobat が FDF をオープンした際に実行される javascript のコードを追加する
- fdf_set_opt — フィールドのオプションを設定する
- fdf_set_status — /STATUS キーの値を設定する
- fdf_set_submit_form_action — フィールドの投稿フォームアクションを設定する
- fdf_set_target_frame — フォームの表示対象となるフレームを設定する
- fdf_set_value — フィールドの値を設定する
- fdf_set_version — FDF ファイルのバージョン番号を設定する
+add a note
User Contributed Notes 20 notes
mitka at actdev.com ¶
22 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.
Dimitri Tarassenko
fleischer at mail dot com ¶
21 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;
}
wesley_grant at yahoo dot com ¶
18 years ago
Changing the
session.cache_limiter
directive in the php.ini file to 'private'
seems to resolve the issue with sending fdf data and session headers at the same time to Internet Explorer.
mirage at rateaprof dot com ¶
21 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.
jeff at cowart dot net ¶
21 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.
bea dot el dot tea at gmail dot com ¶
13 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();
}
}
?>
software at yvanrodrigues dot com ¶
20 years ago
Do not use version 6 of the fdftk.dll (windows) with PHP4.3.4, use the one that comes with PHP.
If you use the newer DLL fdf_create will not return a valid handle.
Toppi at i-Mehl dot De ¶
22 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) {
// 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;
}
g8z at yahoo dot com ¶
20 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";
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);
?>