You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Gilad Denneboom <gi...@gmail.com> on 2013/08/06 12:17:47 UTC

Linking to Embedded Files causes them to appear twice

Hi all,

I hope someone can help me solve this strange issue.
I've created a tool that converts form field buttons to File Attachment
annotations, pointing to a file already embedded in the PDF. This works
fine. The problem is that in this process the embedded files linked to
become "duplicated" and appear twice in the Attachments panel.

The relevant code is this:

    PDPage p = field.getWidget().getPage();
    Object o = embeddedFiles.getNames().get(fileName);
    if (o!=null && o instanceof PDFileSpecification) {
        List<PDAnnotation> annots = p.getAnnotations();
        PDAnnotationFileAttachment newAnnot = new
PDAnnotationFileAttachment();
        newAnnot.setRectangle(field.getWidget().getRectangle());

newAnnot.setAttachementName(PDAnnotationFileAttachment.ATTACHMENT_NAME_PAPERCLIP);
        newAnnot.setTitlePopup(field.getAlternateFieldName());
        newAnnot.setSubject(fileName.split("\\.")[1]);
        newAnnot.setContents(fileName.split("\\.")[1]);
        newAnnot.setFile((PDFileSpecification) o);
        newAnnot.setLocked(true);
        newAnnot.setCreationDate(Calendar.getInstance());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String modDate = "D:"+ sdf.format(new Date()) + "+00'00";
        newAnnot.setModifiedDate(modDate);
        annots.add(newAnnot);
    }

If anyone has any ideas on what might be causing this behaviour, I'll be
glad to hear them...

Thanks in advance!

Gilad