Reputation: 1
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);
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
Upvotes: 0
Views: 1313
Reputation: 1
Seems like I´ve found a workaround that works: Instead of using the Overlay.class use the OverlayPDF.class, which adds some layout to the original PDF so you can overlay the "tif-based" PDF files too. The Interface of OverlayPDF.class seems strange (no methods, just the main()) but it worked with all my test PDF files, here´s the code:
String[] args = {pathInputDoc, pathWatermarkDoc, pathOutputDoc};
OverlayPDF.main(args);
I´m still not exactly sure what is happening in OverlayPDF.class - so if anyone can explain - would be great.
Upvotes: 0