Hi All,
I've been working with the creation of PDFs and then loading them into the PdfViewer, but there is something that we want to do we haven't figure it out yet, maybe you guys can help us.
When we create a Pdf we want to show a date field, so we went and create an PdfTextBoxField and add values to it as it look like a date field, but we make it visible = false, since we don't want to show it yet. So on the PdfViewer we want that a person once it sign on an SignatureField shows the date as a readonly. We have almost all cover except that the formfield that is a date field is not visible unless we create it as visible = true, when we create the PDf and that make the DateFormField clickable and they can type inside of it, and we don't want that.
My Question is, is there any way to make the Pdfviewer.FormField visible?
Thaks for all your help
This is the code we use to add the datefield into the PDF as Visible = false:
private static void AddDateFormField(PdfLoadedForm form,
PdfPageBase page, FormFieldDto field)
{
RectangleF bounds = GetBounds(field);
PdfTextBoxField textBoxField =
new(page, field.FormFieldName)
{
BorderWidth = 0,
Bounds = bounds,
ForeColor = new PdfColor(Color.DarkGray),
BackColor = new PdfColor(Color.Transparent),
//ReadOnly = field.IsReadOnly,
TabIndex = Convert.ToInt32(field.SequenceNo),
TextAlignment = PdfTextAlignment.Left,
ToolTip = field.ToolTip,
DefaultValue = DateTime.Today.ToString(DocumentConstants.YearMonthDayValue, CultureInfo.InvariantCulture),
//Visible = true
Visible = false
};
This is the code we use to update the date and show it:
protected virtual async Task OnSignature_Added(AddSignatureEventArgs args)
{
//Thread.Sleep(100);
if (ViewerFieldCatalog.ContainsKey(args.Id))
{
FormField viewerField = ViewerFieldCatalog[args.Id];
//await PdfViewerElement.ClearSelectionAsync();
//await PdfViewerElement.UpdateFormFieldsAsync(viewerField);
FormFieldDto currentField = GetTemplateField(viewerField.Id);
if (currentField?.DateFormFieldName is not null)
await UpdateAssociatedDate(currentField);
//FormFieldDto nextTemplateField = GetNextTemplateField(currentField);
//if (nextTemplateField is not null)
// await ScrollToNextField(nextTemplateField);
}
await PdfViewerElement.ClearSelectionAsync();
}
protected async Task UpdateAssociatedDate(FormFieldDto templateField)
{
var dateFieldInstaceId = GetIdFromName(templateField.DateFormFieldName);
if (templateField?.DateFormFieldName is not null)
if (ViewerFieldCatalog.TryGetValue(dateFieldInstaceId, out FormField viewerField))
{
viewerField.Value = DateTime.Today.ToString(DocumentConstants.YearMonthDayValue, CultureInfo.InvariantCulture);
//viewerField.Value = DateTime.Now.ToString("MMMM-d, yyyy");
viewerField.IsReadOnly = true;
await PdfViewerElement.UpdateFormFieldsAsync(viewerField);
}
}
Screenshot before and after signing with visible = false :