我需要一些有关代码错误问题的帮助 [英] I Need Some Help With Code Error Problems

查看:73
本文介绍了我需要一些有关代码错误问题的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的问题是对salysle在此页面上标题为使用Visual Basic和iTextSharp DLL的以编程方式完成PDF表单域"的文章的补充.
在ListFieldNames()子例程中,有一段代码:

The following question is in reguards to the article found on this page entitled "Programmatically Complete PDF Form Fields using Visual Basic and the iTextSharp DLL" by salysle.

In the ListFieldNames() Subroutine there is a section of code:

Dim de As New DictionaryEntry

For Each de In pdfReader.AcroFields.Fields
     sb.Append(de.Key.ToString() + Environment.NewLine)
Next



此代码给出以下错误:

类型``System.Collections.Generic.KeyValuePair(Of String,iTextSharp.text.pdf.AcroFields.Item)''的值不能转换为``System.Collections.DictionaryEntry''.

有人建议编写这样的代码:



This code give the error listed below:

Value of type ''System.Collections.Generic.KeyValuePair(Of String, iTextSharp.text.pdf.AcroFields.Item)'' cannot be converted to ''System.Collections.DictionaryEntry''.

Someone else suggested writing the code like this:

Dim de As New DictionaryEntry

For Each de As KeyValuePair(Of String, iTextSharp.text.pdf.AcroFields.Item) In _ pdfReader.AcroFields.Fields
sb.Append(de.Key.ToString() + Environment.NewLine)
Next



但是,当我尝试此操作时,我将收到以下错误:

类型``System.Collections.Generic.KeyValuePair(Of String,iTextSharp.text.pdf.AcroFields.Item)''的值不能转换为``System.Collections.DictionaryEntry''.

如何克服这些错误.我真的很想在我目前正在编写的程序中具有此功能.

作为说明,我正在使用Visual Basic 2010 Express进行编程.



However when I try this I then get the following error:

Value of type ''System.Collections.Generic.KeyValuePair(Of String, iTextSharp.text.pdf.AcroFields.Item)'' cannot be converted to ''System.Collections.DictionaryEntry''.

What can be done to overcome these errors. I would really like to have this feature in the program that I am currently writing.

As a note, I am using Visual Basic 2010 Express for my programming.

推荐答案

如果您拥有itextsharp的新版本,则可以使用以下版本:

昏暗字段作为IDictionary(字符串,iTextSharp.text.pdf.AcroFields.Item)= pdfReader.AcroFields.Fields
对于每个在字段中作为字符串的键.键
sb.Append(key.ToString()+ Environment.NewLine)
下一页
If you have new version of itextsharp, you may use this:

Dim fields As IDictionary(Of String, iTextSharp.text.pdf.AcroFields.Item) = pdfReader.AcroFields.Fields
For Each key As String In fields.Keys
sb.Append(key.ToString() + Environment.NewLine)
Next


尝试一下:

Try this:

For Each de As DictionaryEntry In pdfReader.AcroFields.Fields
     sb.Append(de.Key.ToString() + Environment.NewLine)
Next



请注意,此行不存在:



Notice that this line is NOT there:

Dim de As New DictionaryEntry


Yep that deffinetly fixed the issue. I actually found that all three blocks of code seem to work if you remove the line:

<pre>Dim de As New DictionaryEntry</pre>

I dont fully understand it because I personally never actually declare the variable de. I am assuming that it is somehow declared in the isharptext.dll file.

But long story short, THANK YOU so much for the help. I am back on the road of progress. :-D


这篇关于我需要一些有关代码错误问题的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆