public PDDocument overlay( PDDocument overlay, PDDocument destination ) throws IOException
{
pdfOverlay = overlay;
pdfDocument = destination;
PDDocumentCatalog overlayCatalog = pdfOverlay.getDocumentCatalog();
collectLayoutPages(layoutPages, overlayCatalog.getAllPages() );
COSDictionary saveGraphicsStateDic = new COSDictionary();
saveGraphicsStateStream = new COSStream( saveGraphicsStateDic, pdfDocument.getDocument().getScratchFile() );
OutputStream saveStream = saveGraphicsStateStream.createUnfilteredStream();
saveStream.write( " q\n".getBytes() );
saveStream.flush();
COSDictionary restoreGraphicsStateDic = new COSDictionary();
restoreGraphicsStateStream = new COSStream( saveGraphicsStateDic, pdfDocument.getDocument().getScratchFile() );
OutputStream restoreStream = restoreGraphicsStateStream.createUnfilteredStream();
restoreStream.write( " Q\n".getBytes() );
restoreStream.flush();
PDDocumentCatalog pdfCatalog = pdfDocument.getDocumentCatalog();
processPages( pdfCatalog.getAllPages() );
return pdfDocument;
}