[
https://issues.apache.org/jira/browse/PDFBOX-5797?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tilman Hausherr resolved PDFBOX-5797.
-------------------------------------
Assignee: Tilman Hausherr
Resolution: Fixed
> Kid Widget /DA is ignored in setDefaultAppearance() call
> --------------------------------------------------------
>
> Key: PDFBOX-5797
> URL: https://issues.apache.org/jira/browse/PDFBOX-5797
> Project: PDFBox
> Issue Type: Bug
> Components: AcroForm
> Affects Versions: 2.0.31, 3.0.2 PDFBox
> Reporter: Tilman Hausherr
> Assignee: Tilman Hausherr
> Priority: Major
> Fix For: 2.0.33, 3.0.4 PDFBox, 4.0.0
>
> Attachments: SO79271803.pdf, seija.pdf
>
>
> See attached SO question, the field has one widget as kid with its own /DA
> entry. PDFBox only sets the field /DA entry but AppearanceGeneratorHelper
> will consider widget /DA entries too, which can result in the problem
> described in the SO question when only the field /DA entry gets changed.
> Test code:
> {code:java}
> PDDocument doc = Loader.loadPDF(new File("seija.pdf"));
> PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
> PDFont font = PDType0Font.load(doc, new
> FileInputStream("c:/windows/fonts/arial.ttf"), false);
> PDResources resources = acroForm.getDefaultResources();
> String fontName = resources.add(font).getName();
> PDVariableText field = (PDVariableText) acroForm.getField("main_text");
> field.setDefaultAppearance(field.getDefaultAppearance()
> .replaceAll("/\\w+", "/"
> + fontName));
> field.setValue("Ahoj světe");
> {code}
> Proposed solution in PDVariableText:
> {code:java}
> public void setDefaultAppearance(String daValue)
> {
> getCOSObject().setString(COSName.DA, daValue);
> if (getCOSObject().containsKey(COSName.KIDS))
> {
> for (PDAnnotationWidget widget : getWidgets())
> {
> COSDictionary widgetDict = widget.getCOSObject();
> if (widgetDict.containsKey(COSName.DA))
> {
> widgetDict.setString(COSName.DA, daValue);
> }
> }
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]