[
https://issues.apache.org/jira/browse/PDFBOX-2849?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14610413#comment-14610413
]
Tilman Hausherr commented on PDFBOX-2849:
-----------------------------------------
I propose the following changes for cases there the appearance exists:
PDButton:
{code}
void constructAppearances() throws IOException
{
boolean hasAppearance = false;
COSBase apBase = dictionary.getDictionaryObject(COSName.AP);
if (apBase instanceof COSDictionary)
{
COSDictionary apDict = (COSDictionary) apBase;
COSBase nBase = apDict.getDictionaryObject(COSName.N);
if (nBase instanceof COSDictionary)
{
COSDictionary nDict = (COSDictionary) apBase;
hasAppearance = nDict.size() > 0;
}
}
if (!hasAppearance)
{
// TODO: implement appearance generation for buttons
throw new UnsupportedOperationException("Appearance generation is
not implemented yet, see PDFBOX-2849");
}
}
{code}
PDRadioButton
{code}
void constructAppearances() throws IOException
{
for (PDAnnotationWidget widget : getWidgets())
{
PDAppearanceDictionary appearance = widget.getAppearance();
if (appearance.getNormalAppearance() == null)
{
// TODO: implement appearance generation for radio buttons
throw new UnsupportedOperationException("Appearance generation
is not implemented yet, see PDFBOX-2849");
}
}
}
{code}
This makes it possible to check() the PDCheckbox and setValue() the
PDRadioButton in the file. It fixes three of the four problems I had with the
attached file, which is related to the thread "Migrate form field entries from
one pdf to another" in the user mailing list. (The remaining problem is
PDFBOX-2848)
> implement appearance generation for buttons
> -------------------------------------------
>
> Key: PDFBOX-2849
> URL: https://issues.apache.org/jira/browse/PDFBOX-2849
> Project: PDFBox
> Issue Type: Sub-task
> Components: AcroForm
> Affects Versions: 2.0.0
> Reporter: Tilman Hausherr
> Fix For: 2.0.0
>
> Attachments: TestTemplate.pdf
>
>
> This code
> {code}
> PDField newField =
> tplDoc.getDocumentCatalog().getAcroForm().getField("01.20.Entry1");
> PDCheckbox newCheckBoxField = (PDCheckbox) newField;
> newCheckBoxField.check();
> {code}
> brings this exception:
> {code}
> Exception in thread "main" java.lang.UnsupportedOperationException: not
> implemented
> at
> org.apache.pdfbox.pdmodel.interactive.form.PDButton.constructAppearances(PDButton.java:225)
> at
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:220)
> at
> org.apache.pdfbox.pdmodel.interactive.form.PDCheckbox.setValue(PDCheckbox.java:128)
> at
> org.apache.pdfbox.pdmodel.interactive.form.PDCheckbox.check(PDCheckbox.java:71)
> {code}
> what did work is this:
> {code}
> newCheckBoxField.getCOSObject().setItem(COSName.V, vValue);
> newCheckBoxField.getCOSObject().setItem(COSName.AS, asValue);
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]