Hello! Is there any way to insert a date picker programmatically by using the PDFNet class? I know how to insert text boxes, check boxes and signature widgets but I haven’t figured out a way to insert a date picker like the ones you can insert via the web viewer user interface. Unable to find anything helpful yet browsing the PDFNet api docs.
To create a DatePickerWidget programatically you can use the following code:
// set flags for multiline and required
const flags = new Annotations.WidgetFlags();
flags.set('Required', true);
// create a form field, note that it has to be a Text field
const field = new Annotations.Forms.Field("my_field_name", {
type: 'Tx',
flags,
});
// create a DatePicker widget and associate it with the field we just created
const widgetAnnot = new Annotations.DatePickerWidgetAnnotation(field);
// set position and size
widgetAnnot.PageNumber = 1;
widgetAnnot.X = 100;
widgetAnnot.Y = 100;
widgetAnnot.Width = 50;
widgetAnnot.Height = 20;
//add the form field and widget annotation
annotationManager.getFieldManager().addField(field);
annotationManager.addAnnotation(widgetAnnot);
annotationManager.drawAnnotationsFromList([widgetAnnot]);
Hi Armando! Thank you for the reply. I was actually wanting to create a date picker widget utilizing the full API. Like how I currently create signature widgets using:
Thanks for clarifying. I found this post that shows that to create a date picker using one of our back-end SDKs we simply use a TextWidget with some embedded JavaScript actions. I think this would be the same if you are using PDFNet to create a DatePicker in WebViewer with the fullAPI.
With the “lean” API in WebViewer we provide this nice abstraction of a DatePicker that gives you the actions already built in, but the actual field is just a text field (and internally the DatePicker is just extending the TextWidget).
I’d follow the code sample from that post using the matching PDFNet APIs and it should work.
Let me know if that helps.
Best Regards,
Armando Bollain
Software Developer
PDFTron Systems, Inc.