Class PdfFlattener

java.lang.Object
de.xima.fc.pdf.flatten.PdfFlattener

public final class PdfFlattener extends Object
Helper class to flatten a PDF document. This is copied from PDAcroForm.flatten(), we cannot use that method directly as it it not PDF/UA aware. PDF/UA requires all contents (such as /DO operators produced by the flatten operation) to be inside marked content sections. This class adds such sections. See PDF standard 1.7,section 14.6 (Marked Content) and 14.8.2.2.2 (Specification of Artifacts).

See https://issues.apache.org/jira/browse/PDFBOX-5528?jql=project%20%3D%20PDFBOX. If that issue is resolved, this class can be removed.

Author:
XIMA MEDIA GmbH
  • Constructor Summary

    Constructors
    Constructor
    Description
    PdfFlattener(org.apache.pdfbox.pdmodel.PDDocument document)
    Creates a new flattener that operates on the given document.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    flatten(org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm form)
    This will flatten all form fields.
    void
    flatten(org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm form, boolean refreshAppearances)
    This will flatten all form fields.
    void
    flatten(org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm form, boolean refreshAppearances, List<org.apache.pdfbox.pdmodel.interactive.form.PDField> fields)
    This will flatten the specified form fields.

    Methods inherited from class java.lang.Object

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

    • PdfFlattener

      public PdfFlattener(org.apache.pdfbox.pdmodel.PDDocument document)
      Creates a new flattener that operates on the given document.
      Parameters:
      document - PD document to process.
  • Method Details

    • flatten

      public void flatten(org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm form) throws IOException
      This will flatten all form fields.

      Flattening a form field will take the current appearance and make that part of the pages content stream. All form fields and annotations associated are removed.

      All shapes are enclosed in marked content sections, in order to produce PDF documents that conform to the PDF/UA standard. See PDF standard 1.7,section 14.6 (Marked Content) and 14.8.2.2.2 (Specification of Artifacts).

      Invisible and hidden fields will be skipped and will not become part of the page content stream

      The appearances for the form fields widgets will not be generated

      Parameters:
      form - Form to flatten. Should belong to the document that was passed to the constructor.
      Throws:
      IOException - When a PDF content stream could not be written.
    • flatten

      public void flatten(org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm form, boolean refreshAppearances) throws IOException
      This will flatten all form fields.

      Flattening a form field will take the current appearance and make that part of the pages content stream. All form fields and annotations associated are removed.

      All shapes are enclosed in marked content sections, in order to produce PDF documents that conform to the PDF/UA standard. See PDF standard 1.7,section 14.6 (Marked Content) and 14.8.2.2.2 (Specification of Artifacts).

      Invisible and hidden fields will be skipped and will not become part of the page content stream

      The appearances for the form fields widgets will not be generated

      Parameters:
      form - Form to flatten. Should belong to the document that was passed to the constructor.
      refreshAppearances - if set to true the appearances for the form field widgets will be updated
      Throws:
      IOException - When a PDF content stream could not be written.
    • flatten

      public void flatten(org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm form, boolean refreshAppearances, List<org.apache.pdfbox.pdmodel.interactive.form.PDField> fields) throws IOException
      This will flatten the specified form fields.

      Flattening a form field will take the current appearance and make that part of the pages content stream. All form fields and annotations associated are removed.

      All shapes are enclosed in marked content sections, in order to produce PDF documents that conform to the PDF/UA standard. See PDF standard 1.7,section 14.6 (Marked Content) and 14.8.2.2.2 (Specification of Artifacts).

      Invisible and hidden fields will be skipped and will not become part of the page content stream

      Parameters:
      form - Form to flatten. Should belong to the document that was passed to the constructor.
      fields - List of fields to flatten.
      refreshAppearances - if set to true the appearances for the form field widgets will be updated
      Throws:
      IOException - When a PDF content stream could not be written.