Package org.apache.pdfbox.util
Class LayerUtility
- java.lang.Object
-
- org.apache.pdfbox.util.LayerUtility
-
public class LayerUtility extends java.lang.Object
This class allows to import pages as Form XObjects into a PDF file and use them to create layers (optional content groups).- Version:
- $Revision$
-
-
Constructor Summary
Constructors Constructor Description LayerUtility(PDDocument document)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PDOptionalContentGroup
appendFormAsLayer(PDPage targetPage, PDXObjectForm form, java.awt.geom.AffineTransform transform, java.lang.String layerName)
Places the given form over the existing content of the indicated page (like an overlay).PDDocument
getDocument()
Returns the PDF document we work on.PDXObjectForm
importPageAsForm(PDDocument sourceDoc, int pageNumber)
Imports a page from some PDF file as a Form XObject so it can be placed on another page in the target document.PDXObjectForm
importPageAsForm(PDDocument sourceDoc, PDPage page)
Imports a page from some PDF file as a Form XObject so it can be placed on another page in the target document.void
wrapInSaveRestore(PDPage page)
Some applications may not wrap their page content in a save/restore (q/Q) pair which can lead to problems with coordinate system transformations when content is appended.
-
-
-
Constructor Detail
-
LayerUtility
public LayerUtility(PDDocument document)
Creates a new instance.- Parameters:
document
- the PDF document to modify
-
-
Method Detail
-
getDocument
public PDDocument getDocument()
Returns the PDF document we work on.- Returns:
- the PDF document
-
wrapInSaveRestore
public void wrapInSaveRestore(PDPage page) throws java.io.IOException
Some applications may not wrap their page content in a save/restore (q/Q) pair which can lead to problems with coordinate system transformations when content is appended. This method lets you add a q/Q pair around the existing page's content.- Parameters:
page
- the page- Throws:
java.io.IOException
- if an I/O error occurs
-
importPageAsForm
public PDXObjectForm importPageAsForm(PDDocument sourceDoc, int pageNumber) throws java.io.IOException
Imports a page from some PDF file as a Form XObject so it can be placed on another page in the target document.- Parameters:
sourceDoc
- the source PDF document that contains the page to be copiedpageNumber
- the page number of the page to be copied- Returns:
- a Form XObject containing the original page's content
- Throws:
java.io.IOException
- if an I/O error occurs
-
importPageAsForm
public PDXObjectForm importPageAsForm(PDDocument sourceDoc, PDPage page) throws java.io.IOException
Imports a page from some PDF file as a Form XObject so it can be placed on another page in the target document.- Parameters:
sourceDoc
- the source PDF document that contains the page to be copiedpage
- the page in the source PDF document to be copied- Returns:
- a Form XObject containing the original page's content
- Throws:
java.io.IOException
- if an I/O error occurs
-
appendFormAsLayer
public PDOptionalContentGroup appendFormAsLayer(PDPage targetPage, PDXObjectForm form, java.awt.geom.AffineTransform transform, java.lang.String layerName) throws java.io.IOException
Places the given form over the existing content of the indicated page (like an overlay). The form is enveloped in a marked content section to indicate that it's part of an optional content group (OCG), here used as a layer. This optional group is returned and can be enabled and disabled through methods onPDOptionalContentProperties
.- Parameters:
targetPage
- the target pageform
- the form to placetransform
- the transformation matrix that controls the placementlayerName
- the name for the layer/OCG to produce- Returns:
- the optional content group that was generated for the form usage
- Throws:
java.io.IOException
- if an I/O error occurs
-
-