pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maruan Sahyoun <sahy...@fileaffairs.de>
Subject Re: ClassCastException
Date Wed, 26 Apr 2017 05:56:31 GMT
Hi,



 
> Am 25.04.2017 um 22:17 schrieb John Liston <listonj@asconline.com>:
> 
> Hi PDFBox,
> 
> I get this ClassCastException:
> 
> Exception in thread "main" java.lang.ClassCastException: org.apache.pdfbox.cos.COSDictionary
cannot be cast to org.apache.pdfbox.cos.COSArray
>                at org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm.getFields(PDAcroForm.java:369)
> 
> when reading this PDF document: 
> https://www.dropbox.com/s/lr4u9voq07qr8wr/URLA.PDF?dl=0 
> 
> using this code in PDFBox 2.0.5:
> 
>               public static void main(String[] args) {
>                               PDDocument pdDocument;
>                               try {
>                                              pdDocument = PDDocument.load(new File("c:/temp/URLA.PDF"));
>                               }
>                               catch (Exception e) {
>                                              throw new RuntimeException(e);
>                               }
>                               PDAcroForm pdAcroForm = pdDocument.getDocumentCatalog().getAcroForm();
>                               if (pdAcroForm != null) {
>                                              try {
>                                                             List<PDField> acroFields
= pdAcroForm.getFields();
>                                                             List<PDField> pdFields
= new ArrayList<PDField>();
>                                                             for (PDField pdField : acroFields)
{
>                      // (modify fields)
>                                                             }
>                                                             pdAcroForm.setFields(pdFields);
>                                                             // flatten the document to
get rid of the buttons
>                                                             pdAcroForm.flatten();
>                                              }
>                                              catch (IOException e) {
>                                                             throw new RuntimeException(e);
>                                              }
>                               }
>                }
> 
> What am I doing wrong? It might be related to the document restrictions.  If so, could
the exception message reflect that? 

the field definition in the AcroForm is wrong as the field root is defined as a dictionary
and not as an array as it's required by the PDF spec. How was the form created? I'm asking
because if I create such form using Adobe LiveCycle Designer (there is an XFA definition in
your form) the field root is OK i.e. it's an array. 

Could you open an issue at https://issues.apache.org/jira/browse/PDFBOX? I think we shold
fix that as Adobe Reader and another viewer I tested can open the form just fine. So we should
do the same.

BR
Maruan


> 
> Thanks,
> John Liston
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message