You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (Jira)" <ji...@apache.org> on 2024/04/03 12:00:00 UTC
[jira] [Created] (PDFBOX-5797) Kid Widget /DA is ignored in setDefaultAppearance() call
Tilman Hausherr created PDFBOX-5797:
---------------------------------------
Summary: 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: 3.0.2 PDFBox, 2.0.31
Reporter: Tilman Hausherr
Attachments: 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: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org