You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2024/08/04 14:58:15 UTC
svn commit: r1919670 - in /pdfbox/branches/2.0/pdfbox/src: main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java
Author: msahyoun
Date: Sun Aug 4 14:58:15 2024
New Revision: 1919670
URL: http://svn.apache.org/viewvc?rev=1919670&view=rev
Log:
PDFBOX-5831: fix appearnce when using a numeric value
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java?rev=1919670&r1=1919669&r2=1919670&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java Sun Aug 4 14:58:15 2024
@@ -323,29 +323,24 @@ public abstract class PDButton extends P
@Override
void constructAppearances() throws IOException
{
- List<String> exportValues = getExportValues();
- if (exportValues.size() > 0)
+ for (PDAnnotationWidget widget : getWidgets())
{
- // the value is the index value of the option. So we need to get that
- // and use it to set the value
- try
+ PDAppearanceDictionary appearance = widget.getAppearance();
+ if (appearance == null)
{
- int optionsIndex = Integer.parseInt(getValue());
- if (optionsIndex < exportValues.size())
- {
- updateByOption(exportValues.get(optionsIndex));
- }
- } catch (NumberFormatException e)
+ continue;
+ }
+ PDAppearanceEntry appearanceEntry = appearance.getNormalAppearance();
+ if (((COSDictionary) appearanceEntry.getCOSObject()).containsKey(getCOSObject().getCOSName(COSName.V)))
{
- // silently ignore that
- // and don't update the appearance
+ widget.setAppearanceState(getCOSObject().getCOSName(COSName.V).getName());
+ }
+ else
+ {
+ widget.setAppearanceState(COSName.Off.getName());
}
}
- else
- {
- updateByValue(getValue());
- }
- }
+ }
/**
* Get the values to set individual buttons within a group to the on state.
Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java?rev=1919670&r1=1919669&r2=1919670&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java Sun Aug 4 14:58:15 2024
@@ -24,6 +24,8 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -383,4 +385,48 @@ public class TestRadioButtons
IOUtils.closeQuietly(testPdf);
}
}
+
+ /**
+ * PDFBOX-5831 Numeric value for Opt entry
+ *
+ * @throws IOException
+ * @throws URISyntaxException
+ */
+ @Test
+ public void testPDFBox5831NumericValueForOpt() throws IOException, URISyntaxException
+ {
+ String sourceUrl = "https://issues.apache.org/jira/secure/attachment/13069137/AU_Erklaerung_final.pdf";
+
+ PDDocument testPdf = null;
+ try
+ {
+ testPdf = PDDocument.load(new URL(sourceUrl).openStream());
+ PDAcroForm acroForm = testPdf.getDocumentCatalog().getAcroForm();
+ PDRadioButton field = (PDRadioButton) acroForm.getField("Formular1[0].Seite1[0].TF_P[0].Optionsfeldliste[0]");
+
+ field.setValue(0);
+ assertEquals("1", field.getValue());
+ assertEquals(COSName.getPDFName("0"), field.getCOSObject().getDictionaryObject(COSName.V));
+ assertEquals(0, field.getSelectedIndex());
+
+ field.setValue("1");
+ assertEquals("1", field.getValue());
+ assertEquals(COSName.getPDFName("0"), field.getCOSObject().getDictionaryObject(COSName.V));
+ assertEquals(0, field.getSelectedIndex());
+
+ field.setValue(1);
+ assertEquals("2", field.getValue());
+ assertEquals(COSName.getPDFName("1"), field.getCOSObject().getDictionaryObject(COSName.V));
+ assertEquals(1, field.getSelectedIndex());
+
+ field.setValue("2");
+ assertEquals("2", field.getValue());
+ assertEquals(COSName.getPDFName("1"), field.getCOSObject().getDictionaryObject(COSName.V));
+ assertEquals(1, field.getSelectedIndex());
+ }
+ finally
+ {
+ IOUtils.closeQuietly(testPdf);
+ }
+ }
}
\ No newline at end of file