I have a sample C# code that I actually took it from an article to explain how to list field names from PDF file. The code was taken from here
Before I took the code, I have added the following DLLs to my project's reference:
- itextsharp.dll
- itextsharp.pdfa.dll
- itextsharp.xmlworker.dll
- itextsharp.xtra.dll
Then I created one simple form with one TextBox and I set multiline property to True for the TextBox
On form load, I called a method ListFieldNames()
to list the fields into the TextBox according to the article.
Below is the code:
private void ListFieldNames()
{
string pdfTemplate = "C:\\Users\\aalsahli\\Desktop\\I-9Form.pdf";
this.Text += " - " + pdfTemplate;
PdfReader pdfReader = new PdfReader(pdfTemplate);
StringBuilder sb = new StringBuilder();
foreach (var de in pdfReader.AcroFields.Fields)
{
sb.Append(de.Key.ToString() + Environment.NewLine);
}
textBox1.Text = sb.ToString();
textBox1.SelectionStart = 0;
}
When I run the application, nothing displayed to the TextBox and I didn't get any error message.
When I tried to debug the application, I found out that the code never get in the for loop at all which means the line sb.Append(de.Key.ToString() + Environment.NewLine);
was never executed
Here is the Output that I get when I run the application:
'ReadPDF.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ReadPDF.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\aalsahli\source\repos\ReadPDF\ReadPDF\bin\Debug\ReadPDF.exe'. Symbols loaded.
'ReadPDF.exe' (CLR v4.0.30319: ReadPDF.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ReadPDF.exe' (CLR v4.0.30319: ReadPDF.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ReadPDF.exe' (CLR v4.0.30319: ReadPDF.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ReadPDF.exe' (CLR v4.0.30319: ReadPDF.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ReadPDF.exe' (CLR v4.0.30319: ReadPDF.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ReadPDF.exe' (CLR v4.0.30319: ReadPDF.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ReadPDF.exe' (CLR v4.0.30319: ReadPDF.exe): Loaded 'C:\Users\aalsahli\source\repos\ReadPDF\ReadPDF\bin\Debug\itextsharp.dll'. Module was built without symbols.