Class PdfFormUtilities

java.lang.Object
org.jpedal.examples.BaseExample
org.jpedal.examples.acroform.PdfFormUtilities

public class PdfFormUtilities extends org.jpedal.examples.BaseExample

PdfFormsUtilities

General XFA, Annotations and AcroForm features provided by JPedal grouped into one class to provide simple API

  • Constructor Summary

    Constructors
    Constructor
    Description
    PdfFormUtilities(byte[] byteArray)
    Create a PdfFormUtilities for a PDF held in memory.
    Create a PdfFormUtilities for a PDF file.
  • Method Summary

    Modifier and Type
    Method
    Description
    getFormComponentsFromDocument(String filter, org.jpedal.objects.acroforms.ReturnValues value)
    access the PDF FormObjects (if present) from the open PDF file and return Object values according to ReturnValues.
    getFormComponentsFromPage(String filter, org.jpedal.objects.acroforms.ReturnValues value, int page)
    access the PDF FormObjects (if present) from the page of the open PDF file and return Object values according to ReturnValues.
    int
    number of pages in PDF file (starting at 1)
    byte[]
    getRawXFAData(int dataType)
    access XFA raw data(only works in XFA releases)
    void
    setPassword(String password)
     

    Methods inherited from class org.jpedal.examples.BaseExample

    closePDFfile, openPDFFile

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PdfFormUtilities

      public PdfFormUtilities(String fileName)
      Create a PdfFormUtilities for a PDF file. The file is not opened until BaseExample.openPDFFile() is called.
      Parameters:
      fileName - the path to the PDF file
    • PdfFormUtilities

      public PdfFormUtilities(byte[] byteArray)
      Create a PdfFormUtilities for a PDF held in memory. The PDF is not opened until BaseExample.openPDFFile() is called.
      Parameters:
      byteArray - the bytes of the PDF file
  • Method Details

    • setPassword

      public void setPassword(String password)
      Parameters:
      password - the USER or OWNER password for the PDF file
    • getPageCount

      public int getPageCount()
      number of pages in PDF file (starting at 1)
      Returns:
      page count
    • getFormComponentsFromDocument

      public Object[] getFormComponentsFromDocument(String filter, org.jpedal.objects.acroforms.ReturnValues value) throws PdfException
      access the PDF FormObjects (if present) from the open PDF file and return Object values according to ReturnValues.
      Parameters:
      filter - should be a name, reference or null
      value - enum defining what values to return
      Returns:
      Some examples which all return Object[]

      all forms in document
      getFormComponentsFromDocument(null, ReturnValues.FORMOBJECTS_FROM_REF);
      getFormComponentsFromDocument(null, ReturnValues.FORMOBJECTS_FROM_NAME);

      all formNames
      getFormComponentsFromDocument(null, ReturnValues.FORM_NAMES);

      all forms in document called Mabel (zero values returned if no match)
      getFormComponentsFromDocument("Mabel", ReturnValues.FORMOBJECTS_FROM_NAME);

      a form with PDF Reference 25 0 R (zero values returned if no match)
      getFormComponentsFromDocument("25 0 R", ReturnValues.FORMOBJECTS_FROM_REF);

      any embedded file objects in PDF
      getFormComponentsFromDocument("25 0 R", ReturnValues.EMBEDDED_FILES);

      if you need direct access to the GUI components, you can use (this will also trigger resolving these objects if Swing so we recommend you work with FormObjects unless you explicitly need this)
      getFormComponentsFromDocument(null, ReturnValues.GUI_FORMS_FROM_NAME);

      Throws:
      PdfException - if error in reading pdf file
    • getFormComponentsFromPage

      public Object[] getFormComponentsFromPage(String filter, org.jpedal.objects.acroforms.ReturnValues value, int page) throws PdfException
      access the PDF FormObjects (if present) from the page of the open PDF file and return Object values according to ReturnValues.
      Parameters:
      filter - should be a name, reference or null
      value - should be an enum GUI_FORMS_FROM_NAME, FORM_NAMES, FORMOBJECTS_FROM_NAME,FORMOBJECTS_FROM_REF
      page - will only return forms assigned to this page, or whole document if -1
      Returns:
      Some examples which all return Object[]

      all forms in document
      getFormComponentsFromPage(null, ReturnValues.FORMOBJECTS_FROM_REF, -1);
      getFormComponentsFromPage(null, ReturnValues.FORMOBJECTS_FROM_NAME, -1);

      all forms on page 5
      getFormComponentsFromPage(null, ReturnValues.FORMOBJECTS_FROM_REF, 5);
      getFormComponentsFromPage(null, ReturnValues.FORMOBJECTS_FROM_NAME, 5);

      all formNames
      getFormComponentsFromPage(null, ReturnValues.FORM_NAMES, -1);

      all FormNames of Forms on page 12
      getFormComponentsFromPage(null, ReturnValues.FORMOBJECTS_FROM_REF, 12);

      all forms in document called Mabel (zero values returned if no match)
      getFormComponentsFromPage("Mabel", ReturnValues.FORMOBJECTS_FROM_NAME, -1);

      all forms on page 5 called Mabel (zero values returned if no match)
      getFormComponentsFromPage("Mabel", ReturnValues.FORMOBJECTS_FROM_NAME, 5);

      form with PDF Reference 25 0 R (zero values returned if no match)
      getFormComponentsFromPage("25 0 R", ReturnValues.FORMOBJECTS_FROM_REF, -1);

      form with PDF Reference 25 0 R on page 5 (zero values returned if no match)
      getFormComponentsFromPage("25 0 R", ReturnValues.FORMOBJECTS_FROM_REF, 5);

      if you need direct access to the GUI components, you can use (this will also trigger resolving these objects if Swing so we recommend you work with FormObjects unless you explicitly need this)
      getFormComponentsFromPage(null, ReturnValues.GUI_FORMS_FROM_NAME, -1);
      getFormComponentsFromPage(null, ReturnValues.GUI_FORMS_FROM_NAME, 5);

      Throws:
      PdfException - if error in reading xfa data from pdf file
    • getRawXFAData

      public byte[] getRawXFAData(int dataType) throws PdfException
      access XFA raw data(only works in XFA releases)
      Parameters:
      dataType - PdfDictionary.XFA_CONFIG, PdfDictionary.XFA_DATASET,PdfDictionary.XFA_TEMPLATE
      Returns:
      null or byte[]
      Throws:
      PdfException - if error in reading xfa data from pdf file