既製の PDF ドキュメントのフォーム フィールドに入力したいのですが、実行時に AcroForm で Null Refrence エラーが発生します。
string fileN4 = TextBox1.Text + " LOG.pdf";
File.Copy(Path.Combine(textBox4.Text + "\\", fileN4),
Path.Combine(Directory.GetCurrentDirectory(), fileN4), true);
// Open the file
PdfDocument document = PdfReader.Open(fileN4, PdfDocumentOpenMode.Modify);
PdfTextField currentField = (PdfTextField)(document.AcroForm.Fields["<CASENUM>"]);
//const
string caseName = TextBox1.Text;
PdfString caseNamePdfStr = new PdfString(caseName);
//set the value of this field
currentField.Value = caseNamePdfStr;
// Save the document...
document.Save(fileN4);
エラー PdfTextField currentField = (PdfTextField)(document.AcroForm.Fields["<CASENUM>"]);
が発生する場所も同様です。AcroForm がフィールドを認識さえしていないようです。
別のオプションは、PDF 内のテキストを検索して置換することです (ライセンスのために使用できないため、itextsharp を使用しないでください)。
どんな助けでも素晴らしいでしょう!