pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilad Denneboom <gilad.denneb...@gmail.com>
Subject Re: Duplicating an existing link annotation
Date Thu, 15 Mar 2012 09:12:08 GMT
Hi Sheila,

Thanks for the input... However, this code doesn't compile.
This line:
if (base instanceof PDBorderStyleDictionary){
Produces the following compilation error:
Incompatible conditional operand types COSBase and PDBorderStyleDictionary

Any ideas on how this can be solved?

Thanks again, Gilad.

On Wed, Mar 14, 2012 at 10:55 PM, Sheila M. Morrissey <
Sheila.Morrissey@ithaka.org> wrote:

> I wonder if the PDBorderStyleDictionary didn't end up serialized as an
> indirect object --
> Maybe something like the following would work:
>
> PDBorderStyleDictionary bsd = null;
> COSObjectable cob = newLink.getBorderStyle();
> if (cob instanceof COSObject){
>        COSObject cos = (COSObject)cob;
>        COSBase base = cos.getObject();
>        if (base instanceof PDBorderStyleDictionary){
>                bsd = (PDBorderStyleDictionary) base;
>        }
> }
> else if (cob instanceof PDBorderStyleDictionary){
>        bsd = PDBorderStyleDictionary cob;
> }
> If (bsd != null){
>  // off you go
> }
> else {
>  // hmmm.. what happened to my dictionary?
> }
>
> Sheila
>
>
> -----Original Message-----
> From: Gilad Denneboom [mailto:gilad.denneboom@gmail.com]
> Sent: Sunday, March 11, 2012 5:32 PM
> To: users@pdfbox.apache.org
> Subject: Duplicating an existing link annotation
>
> Hi all,
>
> I'm trying to duplicate an existing link annotation (PDAnnotationLink) from
> one page to others. I'm using this code:
>
>    private static PDAnnotationLink duplicateLink(PDAnnotationLink link,
> PDPage page) {
>        PDAnnotationLink newLink = new PDAnnotationLink();
>        newLink.setAction(link.getAction());
>        newLink.setColour(link.getColour());
>        newLink.setRectangle(link.getRectangle());
>        newLink.setAppearance(link.getAppearance());
>        newLink.setAppearanceStream(link.getAppearanceStream());
>        newLink.setHighlightMode(link.getHighlightMode());
>        newLink.setAnnotationFlags(link.getAnnotationFlags());
>        newLink.setBorderStyle(link.getBorderStyle());
>        newLink.setPage(page);
>        return newLink;
>    }
>
> This works when I run the tool on a file I've created and added some links
> to. HOWEVER, if I then run the result file through the same code, the
> following Exception is thrown:
> Exception in thread "main" java.lang.ClassCastException:
> org.apache.pdfbox.cos.COSObject cannot be cast to
> org.apache.pdfbox.cos.COSDictionary
>    at
>
> org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink.getBorderStyle(PDAnnotationLink.java:131)
>
> Since this is a RunTimeException I can't even catch it and my application
> fails... Any help with this will be appreciated.
> Am I creating the new link in an incorrect way?
>
> Thanks in advance, Gilad.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message