Click here to Skip to main content
11,648,094 members (60,391 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 PDF
Hi guys,

I would just like to ask if it is possible to search and highlight multiple text in a PDF file using C#.

Your advice is very much appreciated. Thank you.
Posted 14-Jun-12 15:26pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Here is a sample VB.NET code to highlight the marked text in PDF:

Private Sub TextMarkButton1_Click()
    '~~> Change this to your File Name
    filey = "c:\test.pdf"
    Set AcroExchApp = CreateObject("AcroExch.App")
    Set AcroExchAVDoc = CreateObject("AcroExch.AVDoc")
 
    '~~> Open the pdf file
    AcroExchAVDoc.Open filey, ""
 
    '~~> Get the PDDoc associated with the open AVDoc
    Set AcroExchPDDoc = AcroExchAVDoc.GetPDDoc
 
    '~~> Search Text
    sustext = "Release"
 
    '~~> get JavaScript Object
    Set jso = AcroExchPDDoc.GetJSObject
 
    '~~> Show application
    AcroExchApp.Show
 
    '~~> Count of Matches Found
    nCount = 0
 
    If Not jso Is Nothing Then
        '~~> Total No of pages in pdf
        nPages = jso.numpages
        '~~> Loop through pages
        For i = 0 To nPages - 1
            '~~> Get words Count in one Page
            nWords = jso.getPageNumWords(i)
            '~~> Loop Thru words in that Page
            For j = 0 To nWords - 1
                '~~> Get each word
                word = Trim(CStr(jso.getPageNthWord(i, j)))
                If word <> "" Then
                    '~~> Match word with Search text
                    result = StrComp(word, sustext, vbTextCompare)
                    '~~ if found, increment count
                    If result = 0 Then nCount = nCount + 1
                End If
            Next j
        Next i
    End If
 
    '~~> Display Number of matches found
    MsgBox nCount
 
    '~~> Clean Up
    Set jso = Nothing
    Set AcroExchAVDoc = Nothing
    Set AcroExchApp = Nothing
End Sub
  Permalink  
Comments
akosidab at 14-Jun-12 21:39pm
   
Hi,

Can you please post the whole code? Coz I don't know the objects you used it causes a lot of errors.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 jyo.net 500
1 F-ES Sitecore 370
2 DamithSL 300
3 OriginalGriff 277
4 CPallini 250
0 OriginalGriff 1,342
1 jyo.net 994
2 DamithSL 981
3 Sergey Alexandrovich Kryukov 893
4 CPallini 845


Advertise | Privacy | Mobile
Web02 | 2.8.150804.4 | Last Updated 22 May 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100