Class PDAcroForm

  • All Implemented Interfaces:
    COSObjectable

    public final class PDAcroForm
    extends Object
    implements COSObjectable
    An interactive form, also known as an AcroForm.
    • Constructor Detail

      • PDAcroForm

        public PDAcroForm​(PDDocument doc)
        Constructor.
        Parameters:
        doc - The document that this form is part of.
      • PDAcroForm

        public PDAcroForm​(PDDocument doc,
                          COSDictionary form)
        Constructor.
        Parameters:
        doc - The document that this form is part of.
        form - The existing acroForm.
    • Method Detail

      • getCOSObject

        public COSDictionary getCOSObject()
        Description copied from interface: COSObjectable
        Convert this standard java object to a COS object.
        Specified by:
        getCOSObject in interface COSObjectable
        Returns:
        The cos object that matches this Java object.
      • importFDF

        public void importFDF​(FDFDocument fdf)
                       throws IOException
        This method will import an entire FDF document into the PDF document that this acroform is part of.
        Parameters:
        fdf - The FDF document to import.
        Throws:
        IOException - If there is an error doing the import.
      • exportFDF

        public FDFDocument exportFDF()
                              throws IOException
        This will export all FDF form data.
        Returns:
        An FDF document used to export the document.
        Throws:
        IOException - If there is an error when exporting the document.
      • getFields

        public List<PDField> getFields()
        This will return all of the documents root fields. A field might have children that are fields (non-terminal field) or does not have children which are fields (terminal fields). The fields within an AcroForm are organized in a tree structure. The documents root fields might either be terminal fields, non-terminal fields or a mixture of both. Non-terminal fields mark branches which contents can be retrieved using PDNonTerminalField.getChildren().
        Returns:
        A list of the documents root fields.
      • setFields

        public void setFields​(List<PDField> fields)
        Set the documents root fields.
        Parameters:
        fields - The fields that are part of the documents root fields.
      • setCacheFields

        public void setCacheFields​(boolean cache)
                            throws IOException
        This will tell this form to cache the fields into a Map structure for fast access via the getField method. The default is false. You would want this to be false if you were changing the COSDictionary behind the scenes, otherwise setting this to true is acceptable.
        Parameters:
        cache - A boolean telling if we should cache the fields.
        Throws:
        IOException - If there is an error while caching the fields.
      • isCachingFields

        public boolean isCachingFields()
        This will tell if this acro form is caching the fields.
        Returns:
        true if the fields are being cached.
      • getField

        public PDField getField​(String fullyQualifiedName)
                         throws IOException
        This will get a field by name, possibly using the cache if setCache is true.
        Parameters:
        fullyQualifiedName - The name of the field to get.
        Returns:
        The field with that name of null if one was not found.
        Throws:
        IOException - If there is an error getting the field type.
      • getDefaultAppearance

        public String getDefaultAppearance()
        Get the default appearance.
        Returns:
        the DA element of the dictionary object
      • setDefaultAppearance

        public void setDefaultAppearance​(String daValue)
        Set the default appearance.
        Parameters:
        daValue - a string describing the default appearance
      • getNeedAppearances

        public boolean getNeedAppearances()
        True if the viewing application should construct the appearances of all field widgets. The default value is false.
        Returns:
        the value of NeedAppearances, false if the value isn't set
      • setNeedAppearances

        public void setNeedAppearances​(Boolean value)
        Set the NeedAppearances value. If this is false, PDFBox will create appearances for all field widget.
        Parameters:
        value - the value for NeedAppearances
      • getDefaultResources

        public PDResources getDefaultResources()
        This will get the default resources for the acro form.
        Returns:
        The default resources.
      • setDefaultResources

        public void setDefaultResources​(PDResources dr)
        This will set the default resources for the acroform.
        Parameters:
        dr - The new default resources.
      • hasXFA

        public boolean hasXFA()
        This will tell if the AcroForm has XFA content.
        Returns:
        true if the AcroForm is an XFA form
      • xfaIsDynamic

        public boolean xfaIsDynamic()
        This will tell if the AcroForm is a dynamic XFA form.
        Returns:
        true if the AcroForm is a dynamic XFA form
      • getXFA

        public PDXFAResource getXFA()
        Get the XFA resource, the XFA resource is only used for PDF 1.5+ forms.
        Returns:
        The xfa resource or null if it does not exist.
      • setXFA

        public void setXFA​(PDXFAResource xfa)
        Set the XFA resource, this is only used for PDF 1.5+ forms.
        Parameters:
        xfa - The xfa resource.
      • getQ

        public int getQ()
        This will get the 'quadding' or justification of the text to be displayed. 0 - Left(default)
        1 - Centered
        2 - Right
        Please see the QUADDING_CONSTANTS.
        Returns:
        The justification of the text strings.
      • setQ

        public void setQ​(int q)
        This will set the quadding/justification of the text. See QUADDING constants.
        Parameters:
        q - The new text justification.
      • isSignaturesExist

        public boolean isSignaturesExist()
        Determines if SignaturesExist is set.
        Returns:
        true if the document contains at least one signature.
      • setSignaturesExist

        public void setSignaturesExist​(boolean signaturesExist)
        Set the SignaturesExist bit.
        Parameters:
        signaturesExist - The value for SignaturesExist.
      • isAppendOnly

        public boolean isAppendOnly()
        Determines if AppendOnly is set.
        Returns:
        true if the document contains signatures that may be invalidated if the file is saved.
      • setAppendOnly

        public void setAppendOnly​(boolean appendOnly)
        Set the AppendOnly bit.
        Parameters:
        appendOnly - The value for AppendOnly.