@douglasdallas
Are you working with a license?
Check how a simpler version of the code works for you.
@douglasdallas
Are you working with a license?
Check how a simpler version of the code works for you.
Yes, the license is being used. Iāve tried the simplified version (as near as via Java) and it doesnāt work for me.
Have you tried in Java with my example and the attached PDF file and you are not seeing the issue?
Thanks for your help.
/*
var doc = new Document(dataDir + "form1.pdf");
TextBoxField tb = doc.Form.Fields[6] as TextBoxField;
Console.WriteLine($"FullName: {tb.FullName}");
tb.Value = "10-Feb-24";
Console.WriteLine($"Result value: {tb.Value}");
doc.Save(dataDir + "Filled-out.pdf");
*/
Document setValueDocument = new Document("/tmp/form_with_field_formatting.pdf");
Field fill_formatted_date1 = setValueDocument.getForm().getFields()[0];
System.out.printf("FullName: %s\n", fill_formatted_date1.getFullName());
fill_formatted_date1.setValue("16-Feb-24");
String theValue = fill_formatted_date1.getValue();
System.out.printf("Result value: %s\n", theValue);
setValueDocument.save("out_simple.pdf");
Not yet, I mostly work in C#.
If necessary, I will do some reproducing in Java, but it will take time.
Still a question - are you using the latest version of the library (24.1 because changes for working with months as strings were added later than getECMAScriptString() on 23.12)?
We are using 2023.12; I will download 2024.01 and try to see if that resolves. Thanks.
It works in 2024.01 - the simple approach of hard coding a value - Iālll see if it works when in our product.
To confirm; what string format for the date should be set? As itās not a date object - I donāt see how it can work with all the display formats?
The customer expects the date to the formatted as per the defined display date.
For example if itās a date only, should it always be set as āMM-dd-yyyyā?
Or should we take the formatting that has been defined as part of the ECMA script and use it? This presents a problem as this date format string is Javascript which is different from Java - so it would need converted somehow.
Thanks
@douglasdallas
I didnāt really understand your question.
Text fields according to the Pdf specification can contain ECMA scripts (java scripts). Which for OnFormat in some way influence (convert) the entered value. The entered data may be formatted as numbers with a certain format, dates, etc.
This can be set, for example, in Acrobat in the text field options.
Sorry, not the best explaination.
How about, from another angle, I have a value in our database which is a date field - and I would like to populate the form field in the PDF. To do this, using your API I need to set the value as a string.
What should the string value be set to, so that it works with any of the display values set within Adobe?
@douglasdallas
Thank you, now I understand your question.
If you are working with a document field about which you donāt know what parameters it has, you can:
int len = "AFDate_FormatEx(\"".Length;
int formatLen = jsString.Length;
string format = jsString.Remove(0, len).Remove(formatLen - len - 2, 2);
var doc = new Document(dataDir + "form1.pdf");
TextBoxField tb = doc.Form.Fields[6] as TextBoxField;
Console.WriteLine($"FullName: {tb.FullName}");
// Set Action.OnFormat to null.
tb.Actions.OnFormat = null;
tb.Value = "Any string";
Console.WriteLine($"Result value: {tb.Value}");
doc.Save(dataDir + "FilledWithAnyString.pdf");
var doc = new Document(dataDir + "form1.pdf");
TextBoxField tb = doc.Form.Fields[6] as TextBoxField;
Console.WriteLine($"FullName: {tb.FullName}");
// Set Action.OnFormat to the desired format.
// Not worked ?
string ECMAScriptString = "AFDate_FormatEx(\"dd/m/yy\")";
tb.Value = "";
tb.Actions.OnFormat = new JavascriptAction(ECMAScriptString);
tb.Value = "19 02 2024";
Console.WriteLine($"Result value: {tb.Value}");
doc.Save(dataDir + "FilledWithAnyString.pdf");
Thanks for your reply. Iām not sure I understand it fully.
Are your steps:
If so, how does Adobe know how to apply the formatting on the date when we re-add it, if it only has the string value and doesnāt know which part of the day, month or year?
not steps, variants
Variant 1. Find out the date format for the text field and generate the assigned string in accordance with this format.
Variant 2. Clear the formatting for the text field and after that you can assign any string to it.
Variant 3. Set some date format for the field and, knowing it, form a suitable string. (Iāll have to check it again and if it doesnāt work Iāll assign a task to the development team).
Ah, gottcha - thanks!
@douglasdallas
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-56612
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.