iTextSharp文件名显示不起作用

时间:2018-05-23 16:55:19

标签: c# pdf itext pdf-form

我有一个示例C#代码,我实际从文章中解释了如何列出PDF文件中的字段名称。代码取自here

在我获取代码之前,我已将以下DLL添加到我的项目参考中:

  • itextsharp.dll
  • itextsharp.pdfa.dll
  • itextsharp.xmlworker.dll
  • itextsharp.xtra.dll

然后我用一个TextBox创建了一个简单的表单,并为TextBox设置了多行属性为 True

在表单加载时,我调用了一个方法ListFieldNames(),根据文章将字段列入TextBox。

以下是代码:

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;
    }

当我运行应用程序时,没有任何内容显示在TextBox上,我也没有收到任何错误消息。

当我尝试调试应用程序时,我发现代码永远不会进入for循环,这意味着行sb.Append(de.Key.ToString() + Environment.NewLine);从未执行过

以下是运行应用程序时获得的输出:

'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.

0 个答案:

没有答案