I think the reasoning is that setting a different string will not ensure the proper format as has been intentef by the forms designer
> Am 24.12.2019 um 20:18 schrieb Tilman Hausherr <thaush...@t-online.de>: > > Hi, > > In the meantime I found the file FreedomExpressions.pdf and amusingly, the JS > content is the same: > > AFDate_FormatEx("mm/dd/yyyy"); > > I agree that we should create the appearance stream. But I still wonder why > the decision was made a long time ago not to. > > Tilman > >> Am 24.12.2019 um 18:07 schrieb Maruan Sahyoun: >> We should be able to remove the test for a JavaScript action and generate >> the appearance regardless. If there is a JavaScript >> action that should take the value and recalculate the entry. What happens >> here (I think as I don't have the form) is that the >> JavaScript is attached to an interactive event which is not triggered which >> results in an empty field. >> >> OTOH this is also a defect of the form itself as the scripting assumes >> interactive use. >> >> If we remove the check we will take the provided string as is and won't >> execute the JavaScript (as we can't) which might lead to >> a visual representation which is not intented e.g. the JavaScript typically >> does date formatting in a way that differs from the >> string being passed. >> >> BTW that's the reasoning why we don't set the appearance if there is a >> JavaScript action attached. >> >> WDYT? >> >> BR >> Maruan >> >> >> >>> Oh, I could reproduce this. >>> >>> Then I debugged it. The code doesn't set the appearance if the /F entry >>> is set. (That is a Javascript action) >>> >>> There is a code comment: >>> >>> PDFormFieldAdditionalActions actions = field.getActions(); >>> >>> // in case all tests fail the field will be formatted by >>> acrobat >>> // when it is opened. See FreedomExpressions.pdf for an >>> example of this. >>> if (actions == null || actions.getF() == null || >>> widget.getCOSObject().getDictionaryObject(COSName.AP) != null) >>> { >>> >>> This code part is from before it became an apache project, I don't have >>> that file, didn't search for the ticket. >>> >>> So remove the /F entry before setting, with >>> >>> field.getActions().setF(null); >>> >>> The drawback is that the "formatter" will be gone. A compromise would be >>> to put it back after setting the field: >>> >>> PDDocument doc = PDDocument.load(...); >>> PDField f = >>> doc.getDocumentCatalog().getAcroForm().getField("dateField"); >>> PDAction fa = f.getActions().getF(); >>> f.getActions().setF(null); >>> f.setValue("01.01.2020"); >>> f.getActions().setF(fa); >>> >>> >>> Tilman >>> >>> Am 24.12.2019 um 16:57 schrieb Robert Pepersack: >>>> Hi Tilman, >>>> I'm using PDFBox version 2.0.17. Here is my code: >>>> >>>> public void fillForm(Map<String, String> formMap) >>>> { >>>> >>>> File file = new File(myFile); >>>> >>>> try (PDDocument doc = PDDocument.load(file)) { >>>> >>>> PDDocumentCatalog docCatalog = doc.getDocumentCatalog(); >>>> PDAcroForm acroForm = docCatalog.getAcroForm(); >>>> >>>> if (acroForm != null) { >>>> >>>> for (Map.Entry<String, String> entry : formMap.entrySet()) { >>>> String key = entry.getKey(); >>>> PDField field = acroForm.getField(key); >>>> >>>> if (field instanceof PDVariableText) { >>>> >>>> if (field instanceof PDTextField) { >>>> PDTextField textField = PDTextField.class.cast(field); >>>> textField.setValue(formMap.get(key)); >>>> >>>> } else if (field instanceof PDChoice) { >>>> PDChoice choice = PDChoice.class.cast(field); >>>> choice.setValue(formMap.get(key)); >>>> >>>> } >>>> } else if (field instanceof PDCheckBox) { >>>> PDCheckBox checkBox = PDCheckBox.class.cast(field); >>>> boolean value = Boolean.valueOf(formMap.get(key)); >>>> if (value) { >>>> checkBox.check(); >>>> } else { >>>> checkBox.unCheck(); >>>> } >>>> >>>> } else if (field instanceof PDRadioButton) { >>>> PDRadioButton radioButton = PDRadioButton.class.cast(field); >>>> radioButton.setValue(formMap.get(key)); >>>> >>>> } >>>> } >>>> >>>> File outputFile = new File("test.pdf"); >>>> doc.save(outputFile); >>>> } >>>> } catch (IOException e) { >>>> throw new AssistBusinessException(e); >>>> } >>>> } >>>> >>>> } >>>> >>>> On Tue, Dec 24, 2019 at 10:43 AM Tilman Hausherr <thaush...@t-online.de> >>>> wrote: >>>> >>>>> Am 23.12.2019 um 22:09 schrieb Robert Pepersack: >>>>>> 2. Run my Java program that loads the .pdf file, populates its form >>>>>> fields, and saves it to a new file on my local disk. >>>>> What code did you use to populate the date field, and what PDFBox >>>>> version did you use (the current version is 2.0.18)? I'm asking because >>>>> the date field does not have an appearance stream. >>>>> >>>>> Tilman >>>>> >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org >>>>> For additional commands, e-mail: users-h...@pdfbox.apache.org >>>>> >>>>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org >>> For additional commands, e-mail: users-h...@pdfbox.apache.org >>> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org > For additional commands, e-mail: users-h...@pdfbox.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org For additional commands, e-mail: users-h...@pdfbox.apache.org