pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Lehmkühler <andr...@lehmi.de>
Subject Re: overwrite a overlay
Date Mon, 26 May 2014 11:26:05 GMT
Hi,


> Skrilay <skrilay@googlemail.com> hat am 23. Mai 2014 um 11:00 geschrieben:
>
>
> Hey guys,
>
> first of all pdfbox is awesome!
> But sadly I’m in that strange situation that I have to delete a watermark
> (sometimes life is bad and you can’t choose the requirements).
> 
> Here is my code which should do this:
>
>       public void setFile(File f) throws IOException {
>               FileInputStream io = new FileInputStream(f);
>               PDDocument doc = PDDocument.load(io);
>               Overlay ov = new Overlay();
>               PDDocument watermarkpdf = new PDDocument();
>               watermarkpdf.addPage(new PDPage());
>               ov.overlay(doc, watermarkpdf);
>               try {
>                       watermarkpdf.save("./docs/" + f.getName());
>               } catch (COSVisitorException e) {
>                       e.printStackTrace();
>               }
>               watermarkpdf.close();
>               doc.close();
>               io.close();
>
>               f = new File("./docs/" + f.getName());
>               this.file = f;
>       }
>
> You know sometimes life is such terrible, here is the result:
>
> Exception in thread "main" 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 importer.Doc.setFile(Doc.java:314)
>       at importer.Parser.createDocs(Parser.java:169)
>       at importer.App.main(App.java:14)
>
> On google I couldn’t find the same scenario and also a bug report regarding to
> this function.
> So what I’m doing wrong? And is it even possible to overwrite a overlay?
I didn't get the point. Why do you try to add an overlayed pdf if your origin
goal is to delete an existing watermark?

A watermark is a special kind of an annotation. The good news is you should
simply remove that annonation and that's it. Bad news is PDFBox doesn't support
watermark annotations. It'll be an instance of PDAnnotationUnknown.

Besides, if you want to overlay pdfs use OverlayPDF instead of Overlay as it
doesn't have the described COSArray limitation.

> Regards,
> Torsten Albert

BR
Andreas Lehmkühler

Mime
View raw message