0

我一直在使用这个问题中给出的建议:

使用 PHP 将 FDF 数据合并为 PDF 文件

确定如何使用从数据库中提取的数据预填充 pdf 表单,但不将数据保存到文件中。我在 Mountain Lion 上运行 php 5.3.15,我使用以下链接将 pdf 与我希望允许用户单击的表格页面上的 fdf 组合到填充的 pdf 文件中:

something.pdf#FDF=generatePdf.php

generatePdf.php 看起来像这样:

<?php
$pdf_form_url= "";
require_once('forge_fdf.php');

$fdf_data_names= array(); // none of these in this example
$fdf_data_strings= array(); // none of these in this example

$fdf_data_strings['form1[0].#subform[0].q1a_LastName'] = "Smith";
$fields_hidden= array();
$fields_readonly= array();

// set this to retry the previous state
$retry_b= false;

header( 'content-type: application/vnd.fdf' );

echo forge_fdf( $pdf_form_url,
    $fdf_data_strings, 
    $fdf_data_names,
    $fields_hidden,
    $fields_readonly );

?>

当我通过 pdftk 命令行运行 FDF 文件时,它看起来像这样:

FieldType: Text
FieldName: form1[0].#subform[0].q1a_LastName[0]
FieldNameAlt: Enter Family Name
FieldFlags: 0
FieldJustification: Left
FieldMaxLength: 35

不过,当我运行它时,表单不会自动填充。我尝试了许多变体,包括仅使用 q1a_LastName 本身,但我仍然得到一个空表单。forge_fdf.php 位于同一目录中。

更新:我还尝试了将 FDF 数据合并到我使用 PHP 链接到的 PDF 问题中概述的传统方法,这意味着我不仅将用户引导到 pdf 文件,而且还试图让用户下载的PDF。在那种特殊情况下,我会收到一条消息说 pdf 是空的。我检查了创建的原始 FDF 文件,它似乎正在填充数据。无论哪种情况,我都没有得到我需要的东西。

4

2 回答 2

0

经过反复试验,我意识到自动填充到链接到 pdf 的 url 的最佳方法是为上面的代码定义 $pdf_form_url 变量。此代码将回显 fdf 文件的详细信息。如果您明确指定 pdf url 是什么,php 和您的浏览器将采取必要的步骤将您链接到 Web 浏览器中的 pdf,其中嵌入的字段信息来自 fdf 输出。

于 2013-02-14T04:28:46.650 回答
0

所以我偶然发现了这个线程,即使我填充了 $pdf_form_url 变量也无法让它工作。这是我的代码:

require_once('forge_fdf.php');  

// leave this blank if we're associating the FDF w/ the PDF via URL
$pdf_form_url= "http://test.pdf";
// $pdf_form_url= "";


// default data; these two arrays must ultimately list all of the fields
// you desire to alter, even if you just want to set the 'hidden' flag;
//
//
$fdf_data_names= array(); // none of these in this example
$fdf_data_strings= array(); // none of these in this example
$fdf_data_strings['Address, Row 1']="XXXX Balboa Arms Drive #XXX, San Diego CA 01234";

$fields_hidden= array();
$fields_readonly= array();

// set this to retry the previous state
$retry_b= false;

header( 'content-type: application/vnd.fdf' );

echo forge_fdf( $pdf_form_url,
        $fdf_data_strings, 
        $fdf_data_names,
        $fields_hidden,
        $fields_readonly );

这是我想使用 pdftk dump_data_fields 更新的表单字段:

FieldType: Text
FieldName: Address, Row 1
FieldNameAlt: (Address, &lt;Row 1&gt;)
FieldFlags: 0
FieldJustification: Center
于 2014-05-02T01:12:30.287 回答