pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Strein, Mark C CIV USARMY TRADOC ANALYSIS CTR (US)" <mark.c.strein....@mail.mil>
Subject Update: org.apache.pdfbox.exceptions.WrappedIOException
Date Thu, 07 Apr 2016 15:06:02 GMT
Hello all,

I hacked my way around it. Used my old software to save the pdf with security removed.
Then did the explorer save to adobe trick.

I would like to make a suggested code change in the PDChoiceField class if I may(see TODO):


public void setValue(String optionValue) throws IOException
    {
    	//TODO - in the instance where an option list doesn't have a default option
        //We need to allow for the case where no selection was made.
        //When reading a blank form, the value returned to us is null. The current code
        //does not handle the possibility of a choice field not being set.
        if(optionValue==null||optionValue.equalsIgnoreCase(""))
        {
            super.setValue("");
            return;
        }
        
        int indexSelected = -1;
        COSArray options = (COSArray) getDictionary().getDictionaryObject(COSName.OPT);
        int fieldFlags = getFieldFlags();
        boolean isEditable = (FLAG_COMBO & fieldFlags) != 0 && (FLAG_EDIT &
fieldFlags) != 0;

        if (options.size() == 0 && !isEditable)
        {
            throw new IOException("Error: You cannot set a value for a choice field if there
are no options.");
        }
        else
        {
            // YXJ: Changed the order of the loops. Acrobat produces PDF's
            // where sometimes there is 1 string and the rest arrays.
            // This code works either way.
            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
                        if ((FLAG_COMBO & fieldFlags) != 0)
                        {
                            super.setValue(value.getString());
                        }
                        else
                        {
                            COSArray indexEntries = new COSArray();
                            indexEntries.add(COSInteger.get((long) i));
                            getDictionary().setItem(COSName.I, indexEntries);
                            setListboxValue(value.getString());
                        }
                        // but then use the key as the V entry
                        getDictionary().setItem(COSName.V, key);
                        indexSelected = i;

                    }
                }
                else
                {
                    COSString value = (COSString) option;
                    if (optionValue.equals(value.getString()))
                    {
                        super.setValue(optionValue);
                        indexSelected = i;
                    }
                }
            }
        }
        if (indexSelected == -1 && isEditable)
        {
            super.setValue(optionValue);
        }
        else if (indexSelected == -1)
        {
            throw new IOException("Error: '" + optionValue + "' was not an available option.");
        }
        else
        {
            COSArray indexArray = (COSArray) getDictionary().getDictionaryObject(COSName.I);
            if (indexArray != null)
            {
                indexArray.clear();
                indexArray.add(COSInteger.get(indexSelected));
            }
        }
    }


V/R,
Mark Strein

TRAC-FLVN
Wargaming and Simulations Directorate
Analytic Tools Division - Paving Crew
Keeper of the Codes
913-684-9309



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


Mime
View raw message