public class Overlay
extends java.lang.Object
implements java.io.Closeable
Modifier and Type | Class and Description |
---|---|
private static class |
Overlay.LayoutPage
Stores the overlay page information.
|
static class |
Overlay.Position
Possible location of the overlaid pages: foreground or background.
|
Constructor and Description |
---|
Overlay() |
Modifier and Type | Method and Description |
---|---|
private void |
addOriginalContent(COSBase contents,
COSArray contentArray) |
protected java.awt.geom.AffineTransform |
calculateAffineTransform(PDPage page,
PDRectangle overlayMediaBox)
Calculate the transform to be used when positioning the overlay.
|
void |
close()
Close all input documents which were used for the overlay and opened by this class.
|
private COSStream |
createCombinedContentStream(COSBase contents) |
private java.util.List<COSStream> |
createContentStreamList(COSBase contents) |
private COSStream |
createOverlayStream(PDPage page,
Overlay.LayoutPage layoutPage,
COSName xObjectId) |
private COSName |
createOverlayXObject(PDPage page,
Overlay.LayoutPage layoutPage) |
private COSStream |
createStream(java.lang.String content) |
private java.lang.String |
float2String(float floatValue) |
java.lang.String |
getDefaultOverlayFile()
Returns the default overlay file.
|
java.lang.String |
getInputFile()
Returns the input file.
|
private Overlay.LayoutPage |
getLayoutPage(int pageNumber,
int numberOfPages) |
private Overlay.LayoutPage |
getLayoutPage(PDDocument doc) |
private java.util.Map<java.lang.Integer,Overlay.LayoutPage> |
getLayoutPages(PDDocument doc) |
private PDDocument |
loadPDF(java.lang.String pdfName) |
private void |
loadPDFs() |
PDDocument |
overlay(java.util.Map<java.lang.Integer,java.lang.String> specificPageOverlayFile)
This will add overlays to a document.
|
PDDocument |
overlayDocuments(java.util.Map<java.lang.Integer,PDDocument> specificPageOverlayDocuments)
This will add overlays documents to a document.
|
private void |
overlayPage(PDPage page,
Overlay.LayoutPage layoutPage,
COSArray array) |
private void |
processPages(PDDocument document) |
void |
setAllPagesOverlayFile(java.lang.String allPagesOverlayFile)
Sets the all pages overlay file.
|
void |
setAllPagesOverlayPDF(PDDocument allPagesOverlayPDF)
Sets the all pages overlay PDF.
|
void |
setDefaultOverlayFile(java.lang.String defaultOverlayFile)
Sets the default overlay file.
|
void |
setDefaultOverlayPDF(PDDocument defaultOverlayPDF)
Sets the default overlay PDF.
|
void |
setEvenPageOverlayFile(java.lang.String evenPageOverlayFile)
Sets the even page overlay file.
|
void |
setEvenPageOverlayPDF(PDDocument evenPageOverlayPDF)
Sets the even page overlay PDF.
|
void |
setFirstPageOverlayFile(java.lang.String firstPageOverlayFile)
Sets the first page overlay file.
|
void |
setFirstPageOverlayPDF(PDDocument firstPageOverlayPDF)
Sets the first page overlay PDF.
|
void |
setInputFile(java.lang.String inputFile)
Sets the file to be overlaid.
|
void |
setInputPDF(PDDocument inputPDF)
Sets the PDF to be overlaid.
|
void |
setLastPageOverlayFile(java.lang.String lastPageOverlayFile)
Sets the last page overlay file.
|
void |
setLastPageOverlayPDF(PDDocument lastPageOverlayPDF)
Sets the last page overlay PDF.
|
void |
setOddPageOverlayFile(java.lang.String oddPageOverlayFile)
Sets the odd page overlay file.
|
void |
setOddPageOverlayPDF(PDDocument oddPageOverlayPDF)
Sets the odd page overlay PDF.
|
void |
setOverlayPosition(Overlay.Position overlayPosition)
Sets the overlay position.
|
private Overlay.LayoutPage defaultOverlayPage
private Overlay.LayoutPage firstPageOverlayPage
private Overlay.LayoutPage lastPageOverlayPage
private Overlay.LayoutPage oddPageOverlayPage
private Overlay.LayoutPage evenPageOverlayPage
private final java.util.Set<PDDocument> openDocuments
private java.util.Map<java.lang.Integer,Overlay.LayoutPage> specificPageOverlayPage
private Overlay.Position position
private java.lang.String inputFileName
private PDDocument inputPDFDocument
private java.lang.String defaultOverlayFilename
private PDDocument defaultOverlay
private java.lang.String firstPageOverlayFilename
private PDDocument firstPageOverlay
private java.lang.String lastPageOverlayFilename
private PDDocument lastPageOverlay
private java.lang.String allPagesOverlayFilename
private PDDocument allPagesOverlay
private java.lang.String oddPageOverlayFilename
private PDDocument oddPageOverlay
private java.lang.String evenPageOverlayFilename
private PDDocument evenPageOverlay
private int numberOfOverlayPages
private boolean useAllOverlayPages
public PDDocument overlay(java.util.Map<java.lang.Integer,java.lang.String> specificPageOverlayFile) throws java.io.IOException
specificPageOverlayFile
- Optional map of overlay files for specific pages. The page
numbers are 1-based. The map must be empty (but not null) if no specific mappings are used.setInputPDF(PDDocument)
then it is that object that is returned.java.io.IOException
- if something went wrongpublic PDDocument overlayDocuments(java.util.Map<java.lang.Integer,PDDocument> specificPageOverlayDocuments) throws java.io.IOException
specificPageOverlayDocuments
- Optional map of overlay documents for specific pages. The
page numbers are 1-based. The map must be empty (but not null) if no specific mappings are
used.setInputPDF(PDDocument)
then it is that object that is returned.java.io.IOException
- if something went wrongpublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- if something went wrongprivate void loadPDFs() throws java.io.IOException
java.io.IOException
private PDDocument loadPDF(java.lang.String pdfName) throws java.io.IOException
java.io.IOException
private Overlay.LayoutPage getLayoutPage(PDDocument doc) throws java.io.IOException
java.io.IOException
private java.util.Map<java.lang.Integer,Overlay.LayoutPage> getLayoutPages(PDDocument doc) throws java.io.IOException
java.io.IOException
private COSStream createCombinedContentStream(COSBase contents) throws java.io.IOException
java.io.IOException
private java.util.List<COSStream> createContentStreamList(COSBase contents) throws java.io.IOException
java.io.IOException
private void processPages(PDDocument document) throws java.io.IOException
java.io.IOException
private void addOriginalContent(COSBase contents, COSArray contentArray) throws java.io.IOException
java.io.IOException
private void overlayPage(PDPage page, Overlay.LayoutPage layoutPage, COSArray array) throws java.io.IOException
java.io.IOException
private Overlay.LayoutPage getLayoutPage(int pageNumber, int numberOfPages)
private COSName createOverlayXObject(PDPage page, Overlay.LayoutPage layoutPage)
private COSStream createOverlayStream(PDPage page, Overlay.LayoutPage layoutPage, COSName xObjectId) throws java.io.IOException
java.io.IOException
protected java.awt.geom.AffineTransform calculateAffineTransform(PDPage page, PDRectangle overlayMediaBox)
page
- The page that will get the overlay.overlayMediaBox
- The overlay media box.private java.lang.String float2String(float floatValue)
private COSStream createStream(java.lang.String content) throws java.io.IOException
java.io.IOException
public void setOverlayPosition(Overlay.Position overlayPosition)
overlayPosition
- the overlay positionpublic void setInputFile(java.lang.String inputFile)
inputFile
- the file to be overlaid. The PDDocument
object gathered from
opening this file will be returned by
overlay(Map<Integer, String>)
.public void setInputPDF(PDDocument inputPDF)
inputPDF
- the PDF to be overlaid. This will be the object that is returned by
overlay(Map<Integer, String>)
.public java.lang.String getInputFile()
public void setDefaultOverlayFile(java.lang.String defaultOverlayFile)
defaultOverlayFile
- the default overlay filepublic void setDefaultOverlayPDF(PDDocument defaultOverlayPDF)
defaultOverlayPDF
- the default overlay PDFpublic java.lang.String getDefaultOverlayFile()
public void setFirstPageOverlayFile(java.lang.String firstPageOverlayFile)
firstPageOverlayFile
- the first page overlay filepublic void setFirstPageOverlayPDF(PDDocument firstPageOverlayPDF)
firstPageOverlayPDF
- the first page overlay PDFpublic void setLastPageOverlayFile(java.lang.String lastPageOverlayFile)
lastPageOverlayFile
- the last page overlay filepublic void setLastPageOverlayPDF(PDDocument lastPageOverlayPDF)
lastPageOverlayPDF
- the last page overlay PDFpublic void setAllPagesOverlayFile(java.lang.String allPagesOverlayFile)
allPagesOverlayFile
- the all pages overlay filepublic void setAllPagesOverlayPDF(PDDocument allPagesOverlayPDF)
allPagesOverlayPDF
- the all pages overlay PDF. This should not be a PDDocument that you
created on the fly, it should be saved first, if it contains any fonts that are subset.public void setOddPageOverlayFile(java.lang.String oddPageOverlayFile)
oddPageOverlayFile
- the odd page overlay filepublic void setOddPageOverlayPDF(PDDocument oddPageOverlayPDF)
oddPageOverlayPDF
- the odd page overlay PDFpublic void setEvenPageOverlayFile(java.lang.String evenPageOverlayFile)
evenPageOverlayFile
- the even page overlay filepublic void setEvenPageOverlayPDF(PDDocument evenPageOverlayPDF)
evenPageOverlayPDF
- the even page overlay PDF