此示例将导致浏览器打开“a.pdf”,并在设置字段值后弹出警报窗口
<?php
header('Content-type: application/vnd.fdf');
$fdf = fdf_create();
fdf_set_file($fdf, 'http://www.example.com/path/to/a.pdf');
fdf_set_value($fdf, 'field1', 'my value');
fdf_set_on_import_javascript($fdf, 'app.alert("executing javascript");', false);
fdf_save($fdf);
fdf_close($fdf);
?>
或者,要在设置字段值之前执行 javascript,只需将 false 更改为 true
<?php
header('Content-type: application/vnd.fdf');
$fdf = fdf_create();
fdf_set_file($fdf, 'http://www.example.com/path/to/a.pdf');
fdf_set_value($fdf, 'field1', 'my value');
fdf_set_on_import_javascript($fdf, 'app.alert("executing javascript");', true);
fdf_save($fdf);
fdf_close($fdf);
?>