Take the 2-minute tour ×

I have the following code

 org.pdfclown.objects.PdfDictionary dict = new org.pdfclown.objects.PdfDictionary();
 org.pdfclown.objects.PdfName name;
 name = dict[org.pdfclown.objects.PdfName.AcroForm];

what i want to do is to see if the loaded file in the application has got the AcroFrom field i was thinking if i could call


in some way as the error that comes up now is

Error   2   Cannot implicitly convert type  
'org.pdfclown.objects.PdfDirectObject' to 'org.pdfclown.objects.PdfName'. 
An explicit conversion exists (are you missing a cast?) 
C:\ImpressionContext (1)\ImpressionContext\ImpressionContext\ContextDialogue.cs 
184 20  ImpressionContext

The original requirement is to detect if the form is AcroForm or if it is an Xfa Form

Is there smeway possible so that i can go to PdfName.AcroForm inside the dictionary and get the value stored in here.

share|improve this question
Your code might be easier to read if you add some using statements at the top of the file, e.g. using org.pdfclown.objects;. –  Mark Byers Dec 21 '12 at 9:15
Try making the title of this question better. –  Erno de Weerd Dec 21 '12 at 9:16
Can't you just cast it with name = (org.pdfclown.objects.PdfName) dict[org.pdfclown.objects.PdfName.AcroForm]? BTW, you REALLY need to start using using statements... –  khellang Dec 21 '12 at 9:17
add comment

2 Answers

The dictionary here returns PdfDirectObject-typed values. What you need to do is cast the returned value to PdfName.

name = dict[org.pdfclown.objects.PdfName.AcroForm] 
             as org.pdfclown.objects.PdfName;
if(name != null) 
    //work with name
share|improve this answer
add comment

the PdfDictionary returns an org.pdfclown.objects.PdfDirectObject object but you want a org.pdfclown.objects.PdfName object. So you need to cast it.

You can use:

name = dict[org.pdfclown.objects.PdfName.AcroForm] 
          as org.pdfclown.objects.PdfName; // Cast it to PdfName
share|improve this answer
add comment

Your Answer


