title: C#: Create PDF Form (AcroForm) using PDFsharp
body: <p>How does one add a PDF Form element to a PDFsharp <code>PdfPage</code> object?</p>
  
  <p>I understand that AcroForm is the best format for form-fillable PDF elements, but the PDFsharp library doesn't seem to allow you to create instances of the AcroForm objects.</p>
  
  <p>I have been able to use PDFsharp to generate simple documents, as here:</p>
  
  <pre><code>static void Main(string[] args) {
      PdfDocument document = new PdfDocument();
      document.Info.Title = "Created with PDFsharp";
  
      // Create an empty page
      PdfPage page = document.AddPage();
  
      // Draw Text
      XGraphics gfx = XGraphics.FromPdfPage(page);
      XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
      gfx.DrawString("Hello, World!", font, XBrushes.Black,
          new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);
  
      // Save document
      const string filename = "HelloWorld.pdf";
      document.Save(filename);
  }
  </code></pre>
  
  <p>But I cannot work out how to add a fillable form element. I gather it would likely use the <code>page.Elements.Add(string key, PdfItem item)</code> method, but how do you make an AcroForm <code>PdfItem</code>? (As classes like <code>PdfTextField</code> do not seem to have a public constructor)</p>
  
  <p>The PDFsharp forums and documentation have not helped with this, and the closest answer I found on Stack Overflow was <a href="https://stackoverflow.com/a/52718014/11002708">this one</a>, which is answering with the wrong library.</p>
  
  <p>So, in short: How would I convert the <code>"Hello World"</code> text above into a text field?</p>
  
  <p>Is it possible to do this in PDFsharp, or should I be using a different C# PDF library? (I would very much like to stick with free - and preferably open-source - libraries)</p>