0

私は以下を利用し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

誰かが私も助けてくれる場合に備えて

4

1 に答える 1

2

PdfDictionaryキーはPdfNameオブジェクトであるため、インデックス演算子が存在する場合、を使用することはできませんstringPdfDictionaryインデックス演算子を実装していないように見えるので、次のようにします。

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ツールを作成し、必要なキーの欠落、nullの必要な値、解析できない日時文字列、および/Foobarの代わりに//Foobarを読み取る辞書の名前を見つけたときに、他のPDFプロデューサーの親の結婚状況を日常的に質問します(ほんの数例を挙げると)。

于 2012-11-29T13:36:40.167 に答える