Class XFAFlattener

java.lang.Object
com.itextpdf.tool.xml.xtra.xfa.XFAFlattener
All Implemented Interfaces:
com.itextpdf.tool.xml.html.CssAppliersAware

public class XFAFlattener extends Object implements com.itextpdf.tool.xml.html.CssAppliersAware
Flattens XFA forms.

Input for flattening can be either PDF document containing XFA forms or XDP stream (a pure XML stream containing XFA description).

To flattenXDP the form (from either PDF or XDP):

  • Create XFAFlattener instance
  • Invoke flatten method
No need to close/dispose flattener afterwards.
  • Constructor Details

    • XFAFlattener

      public XFAFlattener()
  • Method Details

    • flattenXDP

      public void flattenXDP (InputStream xdpStream, OutputStream pdfOutputStream) throws IOException
      Flattens XFA form from XDP stream. For a single instance of XFAFlattener this method could be called only once. Attempt to reuse method will result in throwing a XFAFlattenerUnexpectedUsageException. Declare another XFAFlattener instance to process another XDP.

      Example:
      XFAFlattener flattener = new XFAFlattener();
      FileInputStream fin = new FileInputStream("c:/xdp_source.xml");
      flattener.flattenXDP(fin, new FileOutputStream("my_flat_doc.pdf"));
      fin.close();

      Parameters:
      xdpStream - an XDP stream
      pdfOutputStream - PDF output stream
      Throws:
      IOException - is thrown if an error occurred while reading the XDP input stream
    • flatten

      public void flatten (InputStream xfaInputStream, OutputStream pdfOutputStream) throws IOException, InterruptedException
      Flattens XFA form from PDF For a single instance of XFAFlattener this method could be called only once. Attempt to reuse method will result in throwing a XFAFlattenerUnexpectedUsageException. Declare another XFAFlattener instance to process another PDF.
      Parameters:
      xfaInputStream - the input stream with the PDF containing XFA template
      pdfOutputStream - the output stream where the flattened PDF will be written to
      Throws:
      IOException - is thrown if an error occurred while reading the XFA input stream
      InterruptedException - if the current thread is interrupted by another thread while it is waiting for flatten process, then the wait is ended and an InterruptedException is thrown.
    • flattenXDP

      public void flattenXDP (Document xdpData, OutputStream pdfOutputStream) throws IOException
      Flattens XFA form from XML data. For a single instance of XFAFlattener this method could be called only once. Attempt to reuse method will result in throwing a XFAFlattenerUnexpectedUsageException. Declare another XFAFlattener instance to process another XML.

      Example:
      XFAFlattener flattener = new XFAFlattener();
      File xmlFile = new File("c:/xdp_source.xml");
      DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
      org.w3c.dom.Document xmlDoc = docBuilder.parse(fXmlFile);
      flattener.flattenXDP(xmlDoc, new FileOutputStream("my_flat_doc.pdf"));

      Parameters:
      xdpData - an XML data
      pdfOutputStream - PDF output stream
      Throws:
      IOException - is thrown if an error occurred while reading the XDP input stream
    • setCssAppliers

      public void setCssAppliers (com.itextpdf.tool.xml.html.CssAppliers cssAppliers)
      For internal use only.
      Specified by:
      setCssAppliers in interface com.itextpdf.tool.xml.html.CssAppliersAware
    • getCssAppliers

      public com.itextpdf.tool.xml.html.CssAppliers getCssAppliers()
      For internal use only.
      Specified by:
      getCssAppliers in interface com.itextpdf.tool.xml.html.CssAppliersAware
    • getViewMode

      public XFAFlattener.ViewMode getViewMode()
    • setViewMode

      public XFAFlattener setViewMode (XFAFlattener.ViewMode viewMode)
    • getAppConfig

      public AppConfig getAppConfig()
    • setAppConfig

      public XFAFlattener setAppConfig (AppConfig appConfig)
    • getHostConfig

      public HostConfig getHostConfig()
    • setHostConfig

      public XFAFlattener setHostConfig (HostConfig hostConfig)
    • getDefaultLocale

      public Locale getDefaultLocale()
    • setDefaultLocale

      public XFAFlattener setDefaultLocale (Locale defaultLocale)
    • getExtraEventList

      public List<String> getExtraEventList()
    • setExtraEventList

      public XFAFlattener setExtraEventList (List<String> extraEventList)
    • getHrefResolver

      public com.itextpdf.tool.xml.xtra.xfa.resolver.IHrefResolver getHrefResolver()
    • setHrefResolver

      public XFAFlattener setHrefResolver (com.itextpdf.tool.xml.xtra.xfa.resolver.IHrefResolver hrefResolver)
    • getFontSettings

      public XFAFontSettings getFontSettings()
    • setFontSettings

      public XFAFlattener setFontSettings (XFAFontSettings fontSettings)
    • getFlattenerProperties

      public XFAFlattenerProperties getFlattenerProperties()
    • setFlattenerProperties

      public XFAFlattener setFlattenerProperties (XFAFlattenerProperties flattenerProperties)