java - PDFBOX 1.8.9 Overlay two PDF documents: Layout pages with COSArray currently not supported -
i want use apache pdfbox (1.8.9) library print white/invisible text on existing pdf documents, therefore create new document, add text in color.white , use "overlay" method merge 2 documents together. doing encountered following problem:
java.lang.unsupportedoperationexception: layout pages cosarray not supported. @ org.apache.pdfbox.overlay.collectlayoutpages(overlay.java:269) @ org.apache.pdfbox.overlay.overlay(overlay.java:224) @ com.db.jocr.main.overlay(main.java:194) @ com.db.jocr.main.main(main.java:91)
the code looks 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 code throws exception "overlay.overlay(doc1, doc2)" command
- i found similar question on apache mailinglist (from 2009, apparently no answer, https://mail-archives.apache.org/mod_mbox/pdfbox-users/200902.mbox/%3ccaemknbiammlajehphcegealbaab.bvstone@gmail.com%3e) , comment on stackoverflow (from 2012, watermarking pdfbox)
- it not happen of pdf documents tested -> problem "tif-based" pdf example documents (not "text-based")
- i found hint use "overlaypdf" class -> apparently no longer included in pdfbox 1.8.9
the code apparently "causes" error message not give me hint on how fix that:
cosbase contents = page.getcosdictionary().getdictionaryobject( cosname.contents ); if( contents instanceof cosstream ) { ... } else if( contents instanceof cosarray ) { throw new unsupportedoperationexception("layout pages cosarray not supported."); // layoutpages.add(new layoutpage(contents, res)); }
can explain me difference between cosstream , cosarray , why cosarray-pages not supported?
grateful hint points me right direction,
thanks, daniel
p.s.: project working on is: https://github.com/dbrenk/jocr
edit: ok had wrong: overlaypdf class seems in pdfbox still
seems i´ve found workaround works: instead of using overlay.class use overlaypdf.class, adds layout original pdf can overlay "tif-based" pdf files too. interface of overlaypdf.class seems strange (no methods, main()) worked test pdf files, here´s code:
string[] args = {pathinputdoc, pathwatermarkdoc, pathoutputdoc}; overlaypdf.main(args);
i´m still not sure happening in overlaypdf.class - if can explain - great.
Comments
Post a Comment