Geostyx
Geostyx

Reputation: 101

How do you get existing iTextSharp AcroField actions?

I'm using C#. I've been looking and searching for a way to do this. I've found plenty of examples on ADDING actions to PDF form fields using iTextSharp, but none about reading back existing actions.

I have existing PDF's with form validation (alpha, alphanumeric, etc.) I'm creating a program for filling out these forms, and I need to programmatically check what characters are valid (usually done with JavaScript and REGEX from what I've seen.)

Is there a way to GET this JavaScript so my program can validate the input?

Upvotes: 1

Views: 696

Answers (1)

Geostyx
Geostyx

Reputation: 101

Turns out I need to be reading the full XFA stream to get all the details about form fields.

This code from this answer by this user will get the full XFA stream:

public string ReadXfa(PdfReader reader) {
  XfaForm xfa = new XfaForm(reader);
  XmlDocument doc = xfa.DomDocument;
  reader.Close();

  if (!string.IsNullOrEmpty(doc.DocumentElement.NamespaceURI)) {
    doc.DocumentElement.SetAttribute("xmlns", "");
    XmlDocument new_doc = new XmlDocument();
    new_doc.LoadXml(doc.OuterXml);
    doc = new_doc;
  }

  var sb = new StringBuilder(4000);
  var Xsettings = new XmlWriterSettings() {Indent = true};
  using (var writer = XmlWriter.Create(sb, Xsettings)) {
    doc.WriteTo(writer);
  }
  return sb.ToString();    
}

Upvotes: 1

Related Questions