You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Yonas Jongkind (JIRA)" <ji...@apache.org> on 2009/11/12 00:00:40 UTC

[jira] Created: (PDFBOX-559) PDChoiceField.setValue() does not always work when the choices are not pairs

PDChoiceField.setValue() does not always work when the choices are not pairs
----------------------------------------------------------------------------

                 Key: PDFBOX-559
                 URL: https://issues.apache.org/jira/browse/PDFBOX-559
             Project: PDFBox
          Issue Type: Bug
          Components: PDModel
    Affects Versions: 1.0.0
            Reporter: Yonas Jongkind


I have a PDF that appears to work in Adobe Reader, but for some reason the choices include both strings and pairs. The following code change allows this mixed case to be supported, and also seems to clean up the code a bit.

If you could apply this as a patch in the trunk I would be greatful.


$ svn diff src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceField.java
Index: src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceField.java
===================================================================
--- src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceField.java (revision 832877)
+++ src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceField.java (working copy)
@@ -63,37 +63,34 @@
         }
         else
         {
-            COSBase option = options.getObject( 0 );
-            if( option instanceof COSArray )
-            {
-                for( int i=0; i<options.size() && indexSelected == -1; i++ )
-                {
-                    COSArray keyValuePair = (COSArray)options.get( i );
-                    COSString key = (COSString)keyValuePair.getObject( 0 );
-                    COSString value = (COSString)keyValuePair.getObject( 1 );
-                    if( optionValue.equals( key.getString() ) || optionValue.equals( value.getString() ) )
-                    {
-                        //have the parent draw the appearance stream with the value
-                        super.setValue( value.getString() );
-                        //but then use the key as the V entry
-                        getDictionary().setItem( COSName.getPDFName( "V" ), key );
-                        indexSelected = i;
-                    }
-                }
-            }
-            else
-            {
-                for( int i=0; i<options.size() && indexSelected == -1; i++ )
-                {
-                    COSString value = (COSString)options.get( i );
-                    if( optionValue.equals( value.getString() ) )
-                    {
-                        super.setValue( optionValue );
-                        indexSelected = i;
-                    }
-                }
-            }
+               for( int i=0; i<options.size() && indexSelected == -1; i++ ) {
+                       COSBase option = options.getObject( i );
+                       if( option instanceof COSArray )
+                       {
+                               COSArray keyValuePair = (COSArray)option;
+                               COSString key = (COSString)keyValuePair.getObject( 0 );
+                               COSString value = (COSString)keyValuePair.getObject( 1 );
+                               if( optionValue.equals( key.getString() ) || optionValue.equals( value.getString() ) )
+                               {
+                                       //have the parent draw the appearance stream with the value
+                                       super.setValue( value.getString() );
+                                       //but then use the key as the V entry
+                                       getDictionary().setItem( COSName.getPDFName( "V" ), key );
+                                       indexSelected = i;
+                               }
+                       }
+                       else
+                       {
+                               COSString value = (COSString)option;
+                               if( optionValue.equals( value.getString() ) )
+                               {
+                                       super.setValue( optionValue );
+                                       indexSelected = i;
+                               }
+                       }
+               }
         }
+
         if( indexSelected == -1 )
         {
             throw new IOException( "Error: '" + optionValue + "' was not an available option.");

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-559) PDChoiceField.setValue() does not always work when the choices are not pairs

Posted by "Andreas Lehmkühler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12782079#action_12782079 ] 

Andreas Lehmkühler commented on PDFBOX-559:
-------------------------------------------

Do you have an example pdf?

> PDChoiceField.setValue() does not always work when the choices are not pairs
> ----------------------------------------------------------------------------
>
>                 Key: PDFBOX-559
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-559
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.0.0
>            Reporter: Yonas Jongkind
>
> I have a PDF that appears to work in Adobe Reader, but for some reason the choices include both strings and pairs. The following code change allows this mixed case to be supported, and also seems to clean up the code a bit.
> If you could apply this as a patch in the trunk I would be greatful.
> $ svn diff src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceField.java
> Index: src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceField.java
> ===================================================================
> --- src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceField.java (revision 832877)
> +++ src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoiceField.java (working copy)
> @@ -63,37 +63,34 @@
>          }
>          else
>          {
> -            COSBase option = options.getObject( 0 );
> -            if( option instanceof COSArray )
> -            {
> -                for( int i=0; i<options.size() && indexSelected == -1; i++ )
> -                {
> -                    COSArray keyValuePair = (COSArray)options.get( i );
> -                    COSString key = (COSString)keyValuePair.getObject( 0 );
> -                    COSString value = (COSString)keyValuePair.getObject( 1 );
> -                    if( optionValue.equals( key.getString() ) || optionValue.equals( value.getString() ) )
> -                    {
> -                        //have the parent draw the appearance stream with the value
> -                        super.setValue( value.getString() );
> -                        //but then use the key as the V entry
> -                        getDictionary().setItem( COSName.getPDFName( "V" ), key );
> -                        indexSelected = i;
> -                    }
> -                }
> -            }
> -            else
> -            {
> -                for( int i=0; i<options.size() && indexSelected == -1; i++ )
> -                {
> -                    COSString value = (COSString)options.get( i );
> -                    if( optionValue.equals( value.getString() ) )
> -                    {
> -                        super.setValue( optionValue );
> -                        indexSelected = i;
> -                    }
> -                }
> -            }
> +               for( int i=0; i<options.size() && indexSelected == -1; i++ ) {
> +                       COSBase option = options.getObject( i );
> +                       if( option instanceof COSArray )
> +                       {
> +                               COSArray keyValuePair = (COSArray)option;
> +                               COSString key = (COSString)keyValuePair.getObject( 0 );
> +                               COSString value = (COSString)keyValuePair.getObject( 1 );
> +                               if( optionValue.equals( key.getString() ) || optionValue.equals( value.getString() ) )
> +                               {
> +                                       //have the parent draw the appearance stream with the value
> +                                       super.setValue( value.getString() );
> +                                       //but then use the key as the V entry
> +                                       getDictionary().setItem( COSName.getPDFName( "V" ), key );
> +                                       indexSelected = i;
> +                               }
> +                       }
> +                       else
> +                       {
> +                               COSString value = (COSString)option;
> +                               if( optionValue.equals( value.getString() ) )
> +                               {
> +                                       super.setValue( optionValue );
> +                                       indexSelected = i;
> +                               }
> +                       }
> +               }
>          }
> +
>          if( indexSelected == -1 )
>          {
>              throw new IOException( "Error: '" + optionValue + "' was not an available option.");

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.