Results 1 to 13 of 13

Thread: [RESOLVED] [2003]How to highlight text in pdf

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    44

    Resolved [RESOLVED] [2003]How to highlight text in pdf

    Hai friends,
    I am finding the text in pdf file using Adobe acrobt professional........
    Can any one guide me how to highlight the selected text by vb code

    Thanks in advance,
    Abu

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [2003]How to highlight text in pdf

    How are you interacting with pdf? Can you show me the code?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    44

    Re: [2003]How to highlight text in pdf

    hai koosid

    Code:
            '' filey = "*your full file name including directory here*"
            AcroExchApp = CreateObject("AcroExch.App")
            AcroExchAVDoc = CreateObject("AcroExch.AVDoc")
            ' Open the [strfiley] pdf file
            AcroExchAVDoc.Open(filey, "")       
    
            ' Get the PDDoc associated with the open AVDoc
            AcroExchPDDoc = AcroExchAVDoc.GetPDDoc
            sustext = "accessorizes"
            suktext = "accessorises" 
            ' get JavaScript Object
            ' note jso is related to PDDoc of a PDF,
            jso = AcroExchPDDoc.GetJSObject
            ' count
            nCount = 0
            nCount1 = 0
            gbStop = False
            bUSCnt = False
            bUKCnt = False
            ' search for the text
            If Not jso Is Nothing Then
                ' total number of pages
                nPages = jso.numpages           
                    
                    ' Go through pages
                    For i = 0 To nPages - 1
                        ' check each word in a page
                        nWords = jso.getPageNumWords(i)
                        For j = 0 To nWords - 1
                            ' get a word
    
                            word = Trim(CStr(jso.getPageNthWord(i, j)))
                            'If VarType(word) = VariantType.String Then
                            If word <> "" Then
                                ' compare the word with what the user wants
                                If Trim(sustext) <> "" Then
                                    result = StrComp(word, sustext, vbTextCompare)
                                    ' if same
                                    If result = 0 Then
                                        nCount = nCount + 1
                                        If bUSCnt = False Then
                                            iUSCnt = iUSCnt + 1
                                            bUSCnt = True
                                        End If
                                    End If
                                End If
                                If suktext<> "" Then
                                    result1 = StrComp(word, suktext, vbTextCompare)
                                    ' if same
                                    If result1 = 0 Then
                                        nCount1 = nCount1 + 1
                                        If bUKCnt = False Then
                                            iUKCnt = iUKCnt + 1
                                            bUKCnt = True
                                        End If
                                    End If
                                End If
                            End If
                        Next j
                    Next i
    jso = Nothing
            End If

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [2003]How to highlight text in pdf

    Hi I didn't get the time to work on this till 1 hr ago. but in this one hour I have cleaned your code. This code will now give you the number of times a word occurs in the PDF. I have also taken care of your declaration which were incorrect... Now Let me see if I can highlight the words... Do you want all the word to be highlighted that match the search criteria?

    Code:
    Private Sub CommandButton1_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
    Here is one way to highlight text in PDF using quads...

    http://www.acrobatusers.com/forums/a...c.php?id=14684
    Last edited by Siddharth Rout; Mar 18th, 2009 at 09:51 AM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    44

    Re: [2003]How to highlight text in pdf

    Hai koolsid,
    Thanks for your reply.
    yes, all the words is to be highilghted.

    Thanks in advance,
    abu

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [2003]How to highlight text in pdf

    Did you go thru the link that I posted above?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    44

    Re: [2003]How to highlight text in pdf

    Hai koolsid,
    Thanks ......
    i got the solution through that link......
    i will post my code after i worked out.......

    with regards,
    Abu

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    44

    Re: [2003]How to highlight text in pdf

    hai,
    below code for highlight the word in pdf file using acrobat professional.
    Code:
    Dim pAcroPDPage As Acrobat.AcroPDPage
            Dim avobj As Acrobat.AcroAVDoc
            Dim myPDFPageHiliteObj As Acrobat.AcroHiliteList
            Dim wordToHilite As Acrobat.AcroHiliteList
    
            Dim acroAppObj As Object, PDFDocObj As Object, PDFJScriptObj As Object
            Dim wordHilite As Object, annot As Object, props As Object, RectDim As Object
            Dim colorObject(3) As Object, objRect(3) As Object
            Dim iword As Integer, popupRect(0 To 3) As Integer, iTotalWords As Integer
            Dim numOfPage As Integer, Nthpage As Integer, result As Integer
            Dim word As String, sPath As String
            Dim bUKtext As Boolean, bUStext As Boolean
    
    
    
            acroAppObj = CreateObject("AcroExch.App")
            PDFDocObj = CreateObject("AcroExch.PDDoc")
            avobj = CreateObject("AcroExch.AVDoc")
            myPDFPageHiliteObj = CreateObject("AcroExch.HiliteList")
            wordToHilite = CreateObject("AcroExch.HiliteList")
            myPDFPageHiliteObj.Add(0, 32767)
            ' RectDim = CreateObject("AcroExch.Rect")
            sPath = "E:\00001.pdf"
            PDFDocObj.Open(sPath)
            'to open for testing doc
            'avobj = PDFDocObj.OpenAVDoc("testing")
            ' Hide Acrobat application so everything is done in silent
    
            acroAppObj.Hide()
    
            numOfPage = PDFDocObj.GetNumPAges
    
            
            word = vbNullString
            PDFJScriptObj = Nothing
    
            For Nthpage = 0 To numOfPage - 1
    
                pAcroPDPage = PDFDocObj.AcquirePage(Nthpage)
                wordHilite = pAcroPDPage.CreateWordHilite(myPDFPageHiliteObj)
                PDFJScriptObj = PDFDocObj.GetJSObject
                iTotalWords = wordHilite.GetNumText
                iTotalWords = PDFJScriptObj.getPageNumWords(Nthpage)
                ''check the each word
                For iword = 0 To iTotalWords - 1
    
                    bUStext = False
                    bUKtext = False
                    wordToHilite = CreateObject("AcroExch.HiliteList")
                    wordHilite = pAcroPDPage.CreateWordHilite(myPDFPageHiliteObj)
                    'word = Trim(CStr(PDFJScriptObj.getPageNthWord(Nthpage, iword)))
                    word = PDFJScriptObj.getPageNthWord(Nthpage, iword).ToString.Trim
                    ' word = Trim(word)
                    '' Check to see if the word contains the desired text at the start
                    result = -1
                    If word <> "" Then
    
                        If word = "sample1" Then
                            result = 0
                            bUStext = True
                        End If
    
                        If result <> 0 And bUStext = False Then
                            If word = "sample2" Then
                                result = 0
                                bUKtext = True
                            End If
                        End If
                        If result = 0 Then
                            ''create obj to highlight word
                            wordToHilite.Add(iword, 1)
                            wordHilite = pAcroPDPage.CreateWordHilite(wordToHilite)
                            RectDim = wordHilite.GetBoundingRect
    
                            If Not PDFJScriptObj Is Nothing Then
    
                                popupRect(0) = RectDim.Left
                                popupRect(1) = RectDim.Top
                                popupRect(2) = RectDim.Right
                                popupRect(3) = RectDim.bottom
                                annot = PDFJScriptObj.AddAnnot
                                props = annot.getProps
                                props.Type = "Square"
                                annot.setProps(props)
                                props = annot.getProps
                                ' props.fillColor = PDFJScriptObj.Color.red
                                props.page = Nthpage
                                props.Hidden = False
                                props.Lock = True 'False
                                props.Name = word
                                props.noView = False
                                props.opacity = 0.5
                                props.ReadOnly = True ' False
                                props.Style = "S"
                                props.toggleNoView = False
                                props.popupOpen = False
                                props.rect = popupRect
                                props.popupRect = popupRect
                                If bUStext = True Then
                                    props.strokeColor = PDFJScriptObj.Color.red
                                    props.fillColor = PDFJScriptObj.Color.red
                                ElseIf bUKtext = True Then
                                    props.strokeColor = PDFJScriptObj.Color.blue
                                    props.fillColor = PDFJScriptObj.Color.blue
                                End If
                                annot.setProps(props)
                                wordToHilite = Nothing
                            End If
                        End If
                        word = ""
                    End If
                Next iword
            Next Nthpage

  9. #9
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [2003]How to highlight text in pdf

    Great, Thanks for sharing the solution.

    if your query is solved then do remember to mark your thread resolved
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    44

    Re: [RESOLVED] [2003]How to highlight text in pdf

    hai friends,
    the above code iw working fine.........
    I get this error message, while i run my tool for more than 200 pages pdf file.
    "The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))" can any one help me

  11. #11
    New Member
    Join Date
    Jul 2010
    Posts
    6

    Re: [RESOLVED] [2003]How to highlight text in pdf

    Found this very useful after hours of searching.
    Thank you

  12. #12
    New Member
    Join Date
    Jul 2014
    Posts
    1

    Re: [RESOLVED] [2003]How to highlight text in pdf

    Hi, I cant get this to work in excel 2010. do you have an excel working file for this code?
    Thanks!
    Jaime

  13. #13
    New Member leo_213's Avatar
    Join Date
    Apr 2014
    Posts
    7

    Re: [RESOLVED] [2003]How to highlight text in pdf

    Quote Originally Posted by jaimegranad View Post
    Hi, I cant get this to work in excel 2010. do you have an excel working file for this code?
    Thanks!
    Jaime
    hi ,

    refer to the following tutorials to resolve your problem

    find and highlight selected text within Excel
    find and highlight selected data in Excel in C#.VB.NET
    Hope helpful

    Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width