2012-11-29 26 views
0

我正在使用的PdfDictionary並寫入以下錯誤與使用PdfDictionary

PdfDictionary sv = new PdfDictionary(); 
sv["/Type"] = new PDFName("/SV"); 
sv["/Filter"] = new PDFName("Abc"); 
sv["/Ff"] = new PDFNumber(1); 

signame.Dictionary["/SV"] = sv; 
PDFArray arReasons = new PDFArray(); 
arReasons.Add(new PDFString(string.Format("CToken::{0}", customxml))); 
arReasons.Add(new PDFString(reason)); 
v.Put(PdfName.arReasons); 

但它給了我下面的錯誤搜索了很多,但沒有取得積極成果

Error 1 Cannot apply indexing with [] to an expression of type 'iTextSharp.text.pdf.PdfDictionary' C:\Users\lenovo\Dropbox\updated C# app\WindowsFormsApplication1\WindowsFormsApplication1\Form2.cs 134 17 WindowsFormsApplication1 

其他的錯誤,我得到的是: -

Error 9 'iTextSharp.text.pdf.PdfName' does not contain a definition for 'arReasons' C:\Users\lenovo\Dropbox\updated C# app\WindowsFormsApplication1\WindowsFormsApplication1\Form2.cs 145 32 WindowsFormsApplication1 

Error 3 'string' does not contain a definition for 'Dictionary' and no extension method 'Dictionary' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?) C:\Users\lenovo\Dropbox\updated C# app\WindowsFormsApplication1\WindowsFormsApplication1\Form2.cs 141 25 WindowsFormsApplication1 

Error 8 The name 'reason' does not exist in the current context C:\Users\lenovo\Dropbox\updated C# app\WindowsFormsApplication1\WindowsFormsApplication1\Form2.cs 144 45 WindowsFormsApplication1 

以防萬一有人幫我也

+0

看起來像PdfDictionary類不支持索引,因爲它不公開任何數組類型的行爲。 – ryadavilli

+0

看起來像任何可能的工作 – user1862352

回答

2

PdfDictionary鍵是PdfName對象,所以如果有索引操作符,則不能使用string。由於PdfDictionary不會出現執行索引操作,你可以這樣做:

PdfDictionary sv = new PdfDictionary(); 
sv.Put(PdfName.TYPE, PdfName.SV); 
sv.Put(PdfName.FILTER, new PdfName("Abc")); 
sv.Put(PdfName.FF, new PdfNumber(1)); 

注意使用已經被設定的那些名字,並且你不需要任何前綴名稱字符串與靜態成員一個 '/'。

另外,請確保您檢查輸出的語法和語義。 iTextSharp不會爲你做到這一點(據我所知),最終結果是一個受損的PDF,可能Acrobat會默默接受,但是對於其他PDF使用者來說都是一種痛苦。我編寫PDF工具爲生活和例行公事地質疑其他PDF生產者的父母的婚姻狀況,當我看到丟失的鑰匙是必需的,空要求的值,不可解析的日期時間字符串和名稱在字典中讀取//Foobar而不是/ Foobar (僅舉幾個)。

+0

此外@ user1862352引用PdfName.arReasons。我非常懷疑iTextSharp PdfName類中有這樣一個靜態元素。 – mkl