I want to use the Apache PDFBOX (1.8.9) Library to print white/invisible text on existing PDF documents, therefore I create a new document, add the text in Color.WHITE and use the "overlay" method to merge the two documents together. By doing this I encountered the following problem:
java.lang.UnsupportedOperationException: Layout pages with COSArray currently not supported.
at org.apache.pdfbox.Overlay.collectLayoutPages(Overlay.java:269)
at org.apache.pdfbox.Overlay.overlay(Overlay.java:224)
at com.db.jocr.Main.overlay(Main.java:194)
at com.db.jocr.Main.main(Main.java:91)
The code looks something like this:
realDoc = PDDocument.load(pathInputDoc);
String pathWatermarkDoc = createWhiteOnWhiteDoc(text, pageCount, color);
watermarkDoc = PDDocument.load(pathWatermarkDoc);
Overlay overlay = new Overlay();
overlay.overlay(realDoc,watermarkDoc);
- Line 194 where my code throws the exception is the "overlay.overlay(doc1, doc2)" command
- I found a similar question on the apache mailinglist (from 2009, apparently with no answer, https://mail-archives.apache.org/mod_mbox/pdfbox-users/200902.mbox/%3CCAEMKNBIAMMLAJEHPHCEGEALBAAB.bvstone@gmail.com%3E) and a comment on stackoverflow (from 2012, Watermarking with PDFBox)
- It does not happen with most of the PDF documents I tested -> it specifically is a problem with "tif-based" PDF example documents (not "text-based")
- I also found a hint to use the "OverlayPDF" class -> which is apparently no longer included in PDFBOX 1.8.9
The code that apparently "causes" the error message also does not give me a hint on how to fix that:
COSBase contents = page.getCOSDictionary().getDictionaryObject( COSName.CONTENTS );
if( contents instanceof COSStream )
{
...
}
else if( contents instanceof COSArray )
{
throw new UnsupportedOperationException("Layout pages with COSArray currently not supported.");
// layoutPages.add(new LayoutPage(contents, res));
}
Can somebody explain to me what the difference between COSStream and COSArray is and why COSArray-pages are not supported?
Grateful for any hint that points me into the right direction,
Thanks, Daniel
P.S.: the project I am working on is: https://github.com/dbrenk/JOCR
EDIT: ok I had something wrong: the OverlayPDF Class seems to be in PDFBOX still