Class AnnexPageFitter

java.lang.Object
fr.becpg.repo.report.pdf.AnnexPageFitter

final class AnnexPageFitter extends Object
Re-imposes the pages of an external annex document on A4 pages, scaled down into the area left free by the running header, the component heading and the footer the aggregator stamps afterwards. Stateless, safe for concurrent use.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final float
    Height reserved at the top of a page that also receives a component heading.
    (package private) static final float
    Height reserved at the bottom of a page that receives the pagination footer.
    (package private) static final float
    Height reserved at the top of a page that receives the running header.
    private static final org.apache.commons.logging.Log
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    drawAnnotation(org.apache.pdfbox.pdmodel.PDPageContentStream canvas, org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation annotation)
    Draws the normal appearance of an annotation in its rectangle, as a viewer does.
    private static void
    drawAnnotations(org.apache.pdfbox.pdmodel.PDDocument source, org.apache.pdfbox.pdmodel.PDPage page)
    Draws the visible annotations of a page into its content, then removes them from the page.
    (package private) static org.apache.pdfbox.pdmodel.PDDocument
    fit(org.apache.pdfbox.pdmodel.PDDocument source, float topReserve, float bottomReserve)
    Builds a copy of a document whose pages leave the reserved bands empty.
    private static void
    fitPage(org.apache.pdfbox.pdmodel.PDDocument target, org.apache.pdfbox.multipdf.LayerUtility layerUtility, org.apache.pdfbox.pdmodel.PDDocument source, org.apache.pdfbox.pdmodel.PDPage sourcePage, float topReserve, float bottomReserve)
    Adds to the target document an A4 page showing one source page inside the free area.
    private static void
    refreshFormAppearances(org.apache.pdfbox.pdmodel.PDDocument source)
    Generates the appearance of the form fields a viewer is expected to render itself, so that their value can be drawn into the page.
    private static AffineTransform
    uprightTransform(int rotation, org.apache.pdfbox.pdmodel.common.PDRectangle cropBox)
    Maps the page content, once moved to the origin, to the way a viewer shows it: a page rotation is a clockwise turn applied at display time.

    Methods inherited from class java.lang.Object

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

    • logger

      private static final org.apache.commons.logging.Log logger
    • HEADER_HEIGHT

      static final float HEADER_HEIGHT
      Height reserved at the top of a page that receives the running header.
      See Also:
    • COMPONENT_HEADING_HEIGHT

      static final float COMPONENT_HEADING_HEIGHT
      Height reserved at the top of a page that also receives a component heading.
      See Also:
  • Constructor Details

    • AnnexPageFitter

      private AnnexPageFitter()
  • Method Details

    • fit

      static org.apache.pdfbox.pdmodel.PDDocument fit(org.apache.pdfbox.pdmodel.PDDocument source, float topReserve, float bottomReserve) throws IOException
      Builds a copy of a document whose pages leave the reserved bands empty. Each page keeps its orientation and its aspect ratio, is never enlarged and is centred horizontally. What the annotations show (form fields, signatures, stamps, notes) is drawn into the page first, since only the page content is carried over; links are dropped. The source document is modified by that step.
      Parameters:
      source - the annex document, which must stay open as long as the result is used
      topReserve - the height to leave free at the top of each page, in points
      bottomReserve - the height to leave free at the bottom of each page, in points
      Returns:
      a new document with one A4 page per source page
      Throws:
      IOException - if a page cannot be imported
    • refreshFormAppearances

      private static void refreshFormAppearances(org.apache.pdfbox.pdmodel.PDDocument source)
      Generates the appearance of the form fields a viewer is expected to render itself, so that their value can be drawn into the page.
      Parameters:
      source - the annex document
    • drawAnnotations

      private static void drawAnnotations(org.apache.pdfbox.pdmodel.PDDocument source, org.apache.pdfbox.pdmodel.PDPage page)
      Draws the visible annotations of a page into its content, then removes them from the page.
      Parameters:
      source - the annex document
      page - the page whose annotations are drawn
    • drawAnnotation

      private static void drawAnnotation(org.apache.pdfbox.pdmodel.PDPageContentStream canvas, org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation annotation) throws IOException
      Draws the normal appearance of an annotation in its rectangle, as a viewer does.
      Parameters:
      canvas - the content stream of the page holding the annotation
      annotation - the annotation to draw
      Throws:
      IOException - if the appearance cannot be written
    • fitPage

      private static void fitPage(org.apache.pdfbox.pdmodel.PDDocument target, org.apache.pdfbox.multipdf.LayerUtility layerUtility, org.apache.pdfbox.pdmodel.PDDocument source, org.apache.pdfbox.pdmodel.PDPage sourcePage, float topReserve, float bottomReserve) throws IOException
      Adds to the target document an A4 page showing one source page inside the free area.
      Parameters:
      target - the document being built
      layerUtility - the importer bound to the target document
      source - the annex document
      sourcePage - the page to re-impose
      topReserve - the height to leave free at the top, in points
      bottomReserve - the height to leave free at the bottom, in points
      Throws:
      IOException - if the page cannot be imported
    • uprightTransform

      private static AffineTransform uprightTransform(int rotation, org.apache.pdfbox.pdmodel.common.PDRectangle cropBox)
      Maps the page content, once moved to the origin, to the way a viewer shows it: a page rotation is a clockwise turn applied at display time.
      Parameters:
      rotation - the page rotation, a multiple of 90 between 0 and 270
      cropBox - the visible box of the page
      Returns:
      the transform that turns the content upright