Package fr.becpg.repo.report.pdf
Class AnnexPageFitter
java.lang.Object
fr.becpg.repo.report.pdf.AnnexPageFitter
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
FieldsModifier and TypeFieldDescription(package private) static final floatHeight reserved at the top of a page that also receives a component heading.(package private) static final floatHeight reserved at the bottom of a page that receives the pagination footer.(package private) static final floatHeight reserved at the top of a page that receives the running header.private static final org.apache.commons.logging.Log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voiddrawAnnotation(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 voiddrawAnnotations(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.PDDocumentfit(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 voidfitPage(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 voidrefreshFormAppearances(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 AffineTransformuprightTransform(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.
-
Field Details
-
logger
private static final org.apache.commons.logging.Log logger -
HEADER_HEIGHT
static final float HEADER_HEIGHTHeight reserved at the top of a page that receives the running header.- See Also:
-
COMPONENT_HEADING_HEIGHT
static final float COMPONENT_HEADING_HEIGHTHeight reserved at the top of a page that also receives a component heading.- See Also:
-
FOOTER_HEIGHT
static final float FOOTER_HEIGHTHeight reserved at the bottom of a page that receives the pagination footer.- 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 usedtopReserve- the height to leave free at the top of each page, in pointsbottomReserve- 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 documentpage- 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 annotationannotation- 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 builtlayerUtility- the importer bound to the target documentsource- the annex documentsourcePage- the page to re-imposetopReserve- the height to leave free at the top, in pointsbottomReserve- 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 270cropBox- the visible box of the page- Returns:
- the transform that turns the content upright
-