[ 
https://issues.apache.org/jira/browse/PDFBOX-2470?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14194690#comment-14194690
 ] 

Huynh commented on PDFBOX-2470:
-------------------------------

Hi
I think this is a bug, but may be due to our  way to build a graphical 
signature.
As you can see in attached fichedescriptiveformulaire_8954_signed.pdf, the 
appearance dictionary is an indirect object :
/AP <<
/N 269 0 R
>>
Without the modification, the exception was :
Caused by: java.lang.ClassCastException: org.apache.pdfbox.cos.COSObject cannot 
be cast to org.apache.pdfbox.cos.COSDictionary
        at 
org.apache.pdfbox.pdmodel.PDDocument.addSignature(PDDocument.java:487)

About the NullPointerException (if (dr != null)), I don't remember in which 
case we got it, sorry.

Regards

> Exception in PDDocument.addSignature(PDSignature sigObject, 
> SignatureInterface signatureInterface, SignatureOptions options))
> -----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-2470
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2470
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.8.7
>            Reporter: Huynh
>              Labels: patch
>         Attachments: fichedescriptiveformulaire_8954_signed.pdf
>
>
> Hi
> I have made the following modifications to avoid ClassCastException or 
> NullPointerException in addSignature(PDSignature sigObject, 
> SignatureInterface signatureInterface, SignatureOptions options) :
> {code}
>                         // Appearance Dictionary auslesen und setzen
>                         // MOD_CS
>                         // PDAppearanceDictionary ap = 
>                         //        new 
> PDAppearanceDictionary((COSDictionary)cosBaseDict.getItem(COSName.AP));
>                         // ap.getDictionary().setDirect(true);
>                         // signatureField.getWidget().setAppearance(ap);
>                         COSBase item = cosBaseDict.getItem(COSName.AP);
>                         if (item instanceof COSObject) {
>                               item = ((COSObject) item).getObject();
>                         }
>                       if (item instanceof COSDictionary) {
>                               PDAppearanceDictionary ap = new 
> PDAppearanceDictionary((COSDictionary) item);
>                               ap.getDictionary().setDirect(true);
>                               signatureField.getWidget().setAppearance(ap);
>                       }
>                       
>                         // AcroForm DefaultRessource auslesen und setzen
>                         COSBase dr = cosBaseDict.getItem(COSName.DR);
>                         // MOD_CS
>                         if (dr != null) {
>                               dr.setDirect(true);
>                               dr.setNeedToBeUpdate(true);
>                               acroFormDict.setItem(COSName.DR, dr);
>                         }
> {code}
> Regards



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to