2017-07-13 21 views
0

私はItextSharpを使用してPDFファイルを読み込もうとしていますが、テキストボックスに含まれているテキストは読み取られていません。ItextSharpテキストボックスのテキストを読み取る

助けてください。

PdfDictionary pagedic = pdfRead.GetPageN(page); 
PdfArray annotarray = (PdfArray)PdfReader.GetPdfObject(pagedic.Get(PdfName.ANNOTS)); 
if (annotarray == null || annotarray.Size == 0) 
     continue; 
string Title = ""; 
string Title2 = ""; 
string Content2 = ""; 
foreach (PdfObject A in annotarray.ArrayList) 
{ 
    PdfDictionary AnnotationDictionary = (PdfDictionary)PdfReader.GetPdfObject(A); 
    Title2 += AnnotationDictionary.GetAsString(PdfName.T).ToString() + "\n"; 
    if (AnnotationDictionary.GetAsString(PdfName.CONTENTS)!=null) 
    { 
     Content2 += AnnotationDictionary.GetAsString(PdfName.CONTENTS).ToString() + "\n"; 
    } 
    if (AnnotationDictionary.GetAsString(PdfName.T)!=null) 
    { 
     Title += AnnotationDictionary.GetAsString(PdfName.T).ToString() + "\n"; 
    } 
    if (AnnotationDictionary.GetAsString(PdfName.T)!=null) 
    { 
     txt += AnnotationDictionary.GetAsString(PdfName.T).ToString() + "\n"; 
    }      
    if (AnnotationDictionary.GetAsString(PdfName.CONTENTS)!=null) 
    { 
     txt += PdfName.CONTENTS.ToString() + "\n"; 
    } 
    txt += AnnotationDictionary.GetAsString(PdfName.NOTE) + "\n"; 
    txt += AnnotationDictionary.GetAsString(PdfName.FREETEXT)+"\n"; 
} 
MessageBox.Show(txt); 
MessageBox.Show(Title); 
MessageBox.Show(Title2); 
MessageBox.Show(Content2); 
+0

どのテキストボックスについて話していますか?あなたが参照している注釈のタイプについてより正確に記述してください。 –

+0

テキストフィールドについて話している場合は、コードを捨てて、いくつかのドキュメントを読んでください。テキストボックスのように見えるウィジェットアノテーションによって表現されるテキスト型のフォームフィールドは、その値を '/ Contents'に格納するのではなく、'/V'に格納します。また、ウィジット注釈辞書からその値を取得すべきではなく、フィールド辞書から取得するべきです。 AcroFormのテキストフィールドの値を取得するためのiTextコードは、現在のものよりはるかに簡単ですが、テキストフィールドやテキストアノテーションについて話しているかどうかは不明です。 –

+0

あなたは正しいです、私はテキストフィールドを読み込もうとしています。あなたのコメントをありがとう。私はそれを終えると私はそれを投稿します。 –

答えて

0

問題は、私は、文字列、それはすべきではない などのコンテンツを読んでいたということです。以下のように。 Content Text ToUnicodeString()を使用して問題を解決しました。

annotation.GetAsString(PdfName.CONTENTS).ToUnicodeString(); 
関連する問題