4

私はpdfリーダーを開発しています。PDFで任意の文字列を検索し、対応するページ番号を知りたいです。私はiTextSharpを使用しています。

4

2 に答える 2

1

このようなものが動作するはずです:

// add any string you want to match on
Regex regex = new Regex("the", 
  RegexOptions.IgnoreCase | RegexOptions.Compiled 
);
PdfReader reader = new PdfReader(pdfPath);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
for (int i = 1; i <= reader.NumberOfPages; i++) {
  ITextExtractionStrategy strategy = parser.ProcessContent(
    i, new SimpleTextExtractionStrategy()
  );
  if ( regex.IsMatch(strategy.GetResultantText()) ) {
    // do whatever with corresponding page number i...
  }
}
于 2012-04-22T15:24:59.460 に答える
1

使用するには、現在のページ番号を見つけるために使用Itextsharpできます。Acrobat.dllまず、PDFファイルを開き、Lを使用して文字列を検索します

Acroavdoc.open("Filepath","Temperory title") 

Acroavdoc.FindText("String").

この PDF ファイルで文字列が見つかった場合、カーソルが特定のページに移動し、検索された文字列が強調表示されます。Acroavpageview.GetPageNum()現在のページ番号を取得するために使用します。

Dim AcroXAVDoc As CAcroAVDoc
Dim Acroavpage As AcroAVPageView
Dim AcroXApp As CAcroApp

AcroXAVDoc = CType(CreateObject("AcroExch.AVDoc"), Acrobat.CAcroAVDoc)
AcroXApp = CType(CreateObject("AcroExch.App"), Acrobat.CAcroApp)
AcroXAVDoc.Open(TextBox1.Text, "Original document")
AcroXAVDoc.FindText("String is to searched", True, True, False)
Acroavpage = AcroXAVDoc.GetAVPageView()

Dim x As Integer = Acroavpage.GetPageNum
MsgBox("the string found in page number" & x) 
于 2013-04-23T04:20:20.597 に答える