You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Andreas Lehmkühler (JIRA)" <ji...@apache.org> on 2014/10/15 12:35:34 UTC

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

     [ https://issues.apache.org/jira/browse/PDFBOX-559?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Lehmkühler closed PDFBOX-559.
-------------------------------------
    Resolution: Cannot Reproduce
      Assignee: Andreas Lehmkühler

Closed as we never got a sample 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: AcroForm
>    Affects Versions: 1.0.0
>            Reporter: Yonas Jongkind
>            Assignee: Andreas Lehmkühler
>
> 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 grateful.
> {code}
> $ 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.");
> {code}



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