2

私はPdftkpdftk-php(forge-fdfに基づいています)を使用しています。複数のオプションをドロップダウン テキスト ボックスに入力するために、PDF と結合できる FDF を生成したいと考えています。pdftk-php がデフォルトで機能する方法では、ドロップダウンに単一の値のみが入力されます。配列を渡しても機能しません。

これは、pdftk filename dump_data_fields からの関連する出力です。

FieldType: Choice
FieldName: VehicleIDData1
FieldFlags: 4587520
FieldJustification: Left

PDF 1.2 仕様のこの例によると、ドロップダウンには FDF の /Opt オプションが必要なようです。

%FDF-1.2
1 0 obj <<
/FDF <<
/Fields
[
<<
/T (My Children)
/V (Tali)
/Opt [(Maya) (Adam) (Tali)]
November 12, 1996
: 379
>>
]
/F (Dependents.pdf)
>>
>>
endobj
trailer
<</Root 1 0 R>>
%%EOF

これは、1.7仕様の 717 ページの表でサポートされています。

Opt
array
(Required; choice fields only) An array of options to be presented to the user. Each element of the array can take either of two forms:
•A text string representing one of the available options
•A two-element array consisting of a text string representing one of the available options and a default appearance string for constructing the item’s appearance dynamically at viewing time (see “Variable Text” on page 677)

pdftk-php は /Opt を使用しません。フィールドの値の配列を渡すと、/Kids が使用され、他のドロップダウン エントリには入力されません。代わりに /Opt を使用するようにプログラムを変更しようとしましたが、結果の PDF に違いはありません。私は何を間違っていますか?

protected function forge_fdf_fields( &$fdf,
          &$fdf_data,
          &$fields_hidden,
          &$fields_readonly,
          $accumulated_name,
          $strings_b ) // true <==> $fdf_data contains string data
    //
    // string data is used for text fields, combo boxes and list boxes;
    // name data is used for checkboxes and radio buttons, and
    // /Yes and /Off are commonly used for true and false
{
    if( 0< strlen( $accumulated_name ) ) {
        $accumulated_name.= '.'; // append period seperator
    }

    foreach( $fdf_data as $key => $value ) {
    // we use string casts to prevent numeric strings from being silently converted to numbers
        $fdf.= "<< "; // open dictionary

        if( gettype($value)== 'array' ) { // parent; recurse
            $fdf.= "/T (".$this->escape_pdf_string( (string)$key ).") "; // partial field name
            $fdf .= "/V (" . $this->escape_pdf_string((string)$value[0]) . ") ";

            $fdf .= "/Opt [";
            foreach ($value as $option) {
                $fdf .= "(" . $this->escape_pdf_string((string)$option) . ") ";
            }

            /* This is the older code I'm replacing.
            $fdf.= "/Kids [ ";                                    // open Kids array

            // recurse
            $this->forge_fdf_fields( $fdf,
                $value,
                $fields_hidden,
                $fields_readonly,
                $accumulated_name. (string)$key,
                $strings_b );
            */

            $fdf.= "] "; // close Kids array
        } else {

            // field name
            $fdf.= "/T (".$this->escape_pdf_string( (string)$key ).") ";

            // field value
            if( $strings_b ) { // string
                $fdf.= "/V (".$this->escape_pdf_string( (string)$value ).") ";
            }
            else { // name
                $fdf.= "/V /".$this->escape_pdf_name( (string)$value ). " ";
            }

            // field flags
            $this->forge_fdf_fields_flags( $fdf,
                        $accumulated_name. (string)$key,
                        $fields_hidden,
                        $fields_readonly );
        }
        $fdf.= ">> \x0d"; // close dictionary
    }
}
4

0 に答える 0