You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2017/05/05 14:36:04 UTC
[jira] [Commented] (PDFBOX-3753) setting a RadioButton with export
values does not update the appearance
[ https://issues.apache.org/jira/browse/PDFBOX-3753?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15998410#comment-15998410 ]
ASF subversion and git services commented on PDFBOX-3753:
---------------------------------------------------------
Commit 1794061 from [~msahyoun] in branch 'pdfbox/branches/2.0'
[ https://svn.apache.org/r1794061 ]
PDFBOX-3753: set the radio button value by the index of the widget the /Opts entry refers to.
> setting a RadioButton with export values does not update the appearance
> -----------------------------------------------------------------------
>
> Key: PDFBOX-3753
> URL: https://issues.apache.org/jira/browse/PDFBOX-3753
> Project: PDFBox
> Issue Type: Bug
> Components: AcroForm
> Affects Versions: 2.0.5
> Reporter: Travis Schneeberger
> Assignee: Maruan Sahyoun
> Fix For: 2.0.6, 3.0.0
>
> Attachments: fdpAttachment2.pdf, fdpAttachment2-radio-buttons.pdf, fdpAttachment2-radio-buttons-workaround.pdf
>
>
> Setting a RadioButton with export values does not update the appearance. The attached form has two sets of RadioButtons. One called "Group1" and one called "\_6_ Treatment of Program Inco_nwAbuWIn0JWsW9e68RWN8A". "Group1" is easy to set or unset. I noticed during debugging doesn't have any "ExportValues" and so the value is set in a different way than the other set of RadioButtons. "\_6_ Treatment of Program Inco_nwAbuWIn0JWsW9e68RWN8A" does have ExportValues and this appears to be related to the problems with setting the value.
> For example:
> {code}
> try(PDDocument pdfDocument = PDDocument.load(new File("/Users/travis/Desktop/fdpAttachment2.pdf"))) {
> final PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
> final PDAcroForm acroForm = docCatalog.getAcroForm();
> final PDRadioButton group1Field = (PDRadioButton) acroForm.getField("Group1");
> group1Field.setValue("NIH");
> final PDRadioButton topiField = (PDRadioButton) acroForm.getField("_6_ Treatment of Program Inco_nwAbuWIn0JWsW9e68RWN8A");
> topiField.setValue("Additive");
> pdfDocument.save("/Users/travis/Desktop/fdpAttachment2-radio-buttons.pdf");
> }
> {code}
> Notice in "fdpAttachment2-radio-buttons.pdf" that "Group1" RadioButton has NIH toggled while "\_6_ Treatment of Program Inco_nwAbuWIn0JWsW9e68RWN8A" is not toggled even though "Additive" is a valid value.
> The workaround for this is to set the appearance state (AS). I'm still learning the pdfbox api so I apologize if my workaround is a little strange.
> {code}
> try(PDDocument pdfDocument = PDDocument.load(new File("/Users/travis/Desktop/fdpAttachment2.pdf"))) {
> final PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
> final PDAcroForm acroForm = docCatalog.getAcroForm();
> final PDRadioButton group1Field = (PDRadioButton) acroForm.getField("Group1");
> group1Field.setValue("NIH");
> final PDRadioButton topiField = (PDRadioButton) acroForm.getField("_6_ Treatment of Program Inco_nwAbuWIn0JWsW9e68RWN8A");
> topiField.setValue("Additive");
> //Additive ends up being index 0. If I add an AS with "0" it toggle the Additive radio button
> final int idx = topiField.getExportValues().indexOf((topiField).getValue());
> topiField.getWidgets().forEach(w -> {
> PDAppearanceEntry appearanceEntry = w.getAppearance().getNormalAppearance();
> if (((COSDictionary) appearanceEntry.getCOSObject()).containsKey(String.valueOf(idx))) {
> w.getCOSObject().setName(COSName.AS, String.valueOf(idx));
> }
> });
> pdfDocument.save("/Users/travis/Desktop/fdpAttachment2-radio-buttons-workaround.pdf");
> }
> {code}
> Notice in "fdpAttachment2-radio-buttons-workaround.pdf" both sets of RadioButtons are toggled which is the desired behavior
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org