Thanks for that post!
I just found the solution. There were two problems. First open your PDF with Adobe Acrobat and look in the form fields properties.
There you find its name. In the source code you will find it as "Text5".
The second problem was a NullReferenceException, which comes up in the "set the value of this field" code. The solution is by implementing the form field in Adobe Acrobat to give the field in its properties menu a
defaul value. That does the trick! Now I can fill the fields using C# and PDFSharp.
best regards,
David
Code:
PdfDocument template = PdfReader.Open(strPDFName, PdfDocumentOpenMode.Modify);
if (template.AcroForm.Elements.ContainsKey("/NeedAppearances") == false)
template.AcroForm.Elements.Add("/NeedAppearances", new PdfSharp.Pdf.PdfBoolean(true));
PdfTextField currentField = (PdfTextField)(template.AcroForm.Fields["Text5"]);
//const
string caseName = "Hallo";
PdfString caseNamePdfStr = new PdfString(caseName);
//set the value of this field
currentField.Value = caseNamePdfStr;
// Save the document...
template.Save(strPDFName);