public class LayerUtility
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private PDFCloneUtility |
cloner |
private static boolean |
DEBUG |
private static org.apache.commons.logging.Log |
LOG |
private static java.util.Set<java.lang.String> |
PAGE_TO_FORM_FILTER |
private PDDocument |
targetDoc |
Constructor and Description |
---|
LayerUtility(PDDocument document)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
PDOptionalContentGroup |
appendFormAsLayer(PDPage targetPage,
PDFormXObject 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.
|
private void |
importOcProperties(PDDocument srcDoc)
Imports OCProperties from source document to target document so hidden layers can still be
hidden after import.
|
PDFormXObject |
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.
|
PDFormXObject |
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.
|
private void |
transferDict(COSDictionary orgDict,
COSDictionary targetDict,
java.util.Set<java.lang.String> filter,
boolean inclusive) |
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.
|
private static final org.apache.commons.logging.Log LOG
private static final boolean DEBUG
private final PDDocument targetDoc
private final PDFCloneUtility cloner
private static final java.util.Set<java.lang.String> PAGE_TO_FORM_FILTER
public LayerUtility(PDDocument document)
document
- the PDF document to modifypublic PDDocument getDocument()
public void wrapInSaveRestore(PDPage page) throws java.io.IOException
page
- the pagejava.io.IOException
- if an I/O error occurspublic PDFormXObject importPageAsForm(PDDocument sourceDoc, int pageNumber) throws java.io.IOException
You may want to call wrapInSaveRestore(PDPage)
before invoking the Form XObject to
make sure that the graphics state is reset.
sourceDoc
- the source PDF document that contains the page to be copiedpageNumber
- the page number of the page to be copiedjava.io.IOException
- if an I/O error occurspublic PDFormXObject importPageAsForm(PDDocument sourceDoc, PDPage page) throws java.io.IOException
You may want to call wrapInSaveRestore(PDPage)
before invoking the Form XObject to
make sure that the graphics state is reset.
sourceDoc
- the source PDF document that contains the page to be copiedpage
- the page in the source PDF document to be copiedjava.io.IOException
- if an I/O error occurspublic PDOptionalContentGroup appendFormAsLayer(PDPage targetPage, PDFormXObject form, java.awt.geom.AffineTransform transform, java.lang.String layerName) throws java.io.IOException
PDOptionalContentProperties
.
You may want to call wrapInSaveRestore(PDPage)
before calling this method to make
sure that the graphics state is reset.
targetPage
- the target pageform
- the form to placetransform
- the transformation matrix that controls the placement of your form. You'll
need this if your page has a crop box different than the media box, or if these have negative
coordinates, or if you want to scale or adjust your form.layerName
- the name for the layer/OCG to producejava.io.IOException
- if an I/O error occursprivate void transferDict(COSDictionary orgDict, COSDictionary targetDict, java.util.Set<java.lang.String> filter, boolean inclusive) throws java.io.IOException
java.io.IOException
private void importOcProperties(PDDocument srcDoc) throws java.io.IOException
sourceDoc
- The source PDF document that contains the /OCProperties to be copied.java.io.IOException
- If an I/O error occurs.