Class PdfFormFieldMergeUtil

java.lang.Object
com.itextpdf.forms.fields.PdfFormFieldMergeUtil

public final class PdfFormFieldMergeUtil extends Object
Utility class to merge form fields PdfFormField with the same names.
  • Method Details

    • mergeKidsWithSameNames

      public static void mergeKidsWithSameNames (PdfFormField parentField, boolean throwExceptionOnError)
      This method merges all kids with the same names for the given parent field dictionary (recursively).
      Parameters:
      parentField - a field whose kids should be checked and merged in case of same partial names.
      throwExceptionOnError - true if the exception is expected after the merge failed, false if log is expected.
    • mergeTwoFieldsWithTheSameNames

      public static boolean mergeTwoFieldsWithTheSameNames (PdfFormField firstField, PdfFormField secondField, boolean throwExceptionOnError)
      This method merges different values from two field dictionaries into the first one and combines kids.
      Parameters:
      firstField - a field into which dictionary all values will be merged.
      secondField - a field whose values should be merged into the first dictionary.
      throwExceptionOnError - true if the exception is expected after the merge failed, false if log is expected.
      Returns:
      true if fields is successfully merged, false otherwise.
    • getPartialName

      public static String getPartialName (AbstractPdfFormField field)
      Gets partial name for the field dictionary.
      Parameters:
      field - field to get name from.
      Returns:
      field partial name. Also, null if passed dictionary is a pure widget, empty string in case it is a field with no /T entry.
    • processDirtyAnnotations

      public static void processDirtyAnnotations (PdfFormField parentField, boolean throwExceptionOnError)
      Sometimes widgets contain field related keys, and they are the same as these field keys at parent. During merge process we get something like: ParentField (/DA /Ft /T /Kids ) -> Field (/DA /Kids ) -> Annotation (without any form fields)

      This method combines ParentField with Field.

      Parameters:
      parentField - a field whose form field kids should be checked and merged with parent in case all their dictionary values (except Parent and Kids) are the same or parent is a radio button.
      throwExceptionOnError - true if the exception is expected after the merge failed, false if log is expected.
    • mergeFormFields

      public static void mergeFormFields (PdfFormField firstField, PdfFormField secondField, boolean throwExceptionOnError)
      This method combines two form fields.
      Parameters:
      firstField - first form field to be merged
      secondField - second form field to be merged
      throwExceptionOnError - define whether exception (true) or log (false) is expected in case kid with the same name exists and merge of two kids failed.