• Bookmark at: Del.icio.us
  • Bookmark at: Mister Wong
  • Bookmark at: Linkarena
  • Bookmark at: Digg
  • Bookmark at: Yahoo
  • Bookmark at: Google
  • Bookmark at: Icio

Manuals

 

SetaPDF_Merger::setFormFieldNamesCallback()

Description

class SetaPDF_Merger extends SetaPDF {
void setFormFieldNamesCallback ( callback $formFieldNamesCallback ) }

The API renames PDF form fields by default by adding an underscore and the unique file identification number to the end of the form fields name. With this method you can get control of this behaviour by passing a callback function/method to it, which will be called when a form field name is handled.

In the function/method you can create your own logic for renaming the form fields or simply left their names as they are.

Parameters

$formFieldNamesCallback

A callback function or method which will be called when a name of a form field occurs.

The passed argument is of the pseudo-type callback and will be used with call_user_func()-function.

The SetaPDF-Merger API will call your given function/method with the following parameter:

  • (string)$fieldName - Could be in UTF16-BE or PDFDocEncoding/cp1252.
  • (integer)$currentFileId
  • (string)$fileName

The function/method has to return the new field name or false to leave the name as it is.

A prototype of a callback function could look like this (default behaviour):

function makeUniqueFieldName($fieldName, $fileId, $fileName) {
   // Check for UTF-16
   if (strlen($fieldName) > 1 && substr($fieldName,0,2) === "\xFE\xFF") {
       return $fieldName."\x00_\x00".$fileId;
   } else {
       return $fieldName.'_'.$fileId;
   }
}

$merger->setFormFieldNamesCallback('makeUniqueFieldName');

If the form field names shouldn't be changed just return false:

function makeUniqueFieldName($fieldName, $fileId, $fileName) {
   return false;
}
$merger->setFormFieldNamesCallback('makeUniqueFieldName');

Version

Available since Version 1.5