Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Search a PDF and add links to text strings
  FAQ FAQ  Forum Search   Register Register  Login Login

Search a PDF and add links to text strings

 Post Reply Post Reply
Author
Message
jjohnston View Drop Down
Beginner
Beginner


Joined: 17 Dec 05
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote jjohnston Quote  Post ReplyReply Direct Link To This Post Topic: Search a PDF and add links to text strings
    Posted: 25 Jun 07 at 11:52AM
Is there an easy way search a PDF for a specific text string and link it to a URL then save out the new PDF?

For example.  Say I want to search a PDF for the word "Yahoo" and I want to modify it so that the word "Yahoo" is linked to http://www.yahoo.com.

Any help greatly appreciated...


Edited by jjohnston - 25 Jun 07 at 11:58AM
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 25 Jun 07 at 2:28PM
Hi!
Searching the text isn't a problem. Linking textstrings with urls isn't difficult, too. Doing both together in an existing pdf-document is nearly unbeleavable. Have a look in pdf-structures then you know what i mean.
Welcome here and best regards,
Ingo

Back to Top
jjohnston View Drop Down
Beginner
Beginner


Joined: 17 Dec 05
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote jjohnston Quote  Post ReplyReply Direct Link To This Post Posted: 25 Jun 07 at 3:11PM
Originally posted by Ingo Ingo wrote:

Hi!
Searching the text isn't a problem. Linking textstrings with urls isn't difficult, too. Doing both together in an existing pdf-document is nearly unbeleavable. Have a look in pdf-structures then you know what i mean.
Welcome here and best regards,
Ingo



How would you link a text string?  If I can write a new string to the page over the old one in another layer that would work right?

Or maybe a transparent link over the top of the text I want to link?

GetPageText returns the coordinates.  I just need to know the function for linking that region of the page to a specific URL.  :)

Thanks for the quick reply.

-jjohnston


Edited by jjohnston - 25 Jun 07 at 7:44PM
Back to Top
jjohnston View Drop Down
Beginner
Beginner


Joined: 17 Dec 05
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote jjohnston Quote  Post ReplyReply Direct Link To This Post Posted: 25 Jun 07 at 7:43PM
I was hoping for something more elegant but this is what I've come up with.
If anyone else has any ideas for improving this I'd love to hear them.  :)

--------------------------------------
Private Function AddLinks(lPage As Long, sSearchText As String, sLink As String)
    Dim lTmp     As Long
    Dim aWords() As String, aParams() As String
    Dim dLeft    As Double, dTop As Double, dWidth As Double, dHeight As Double

    If m_pdf.SelectedPage <> lPage Then
        m_pdf.SelectPage lPage
    End If
    aWords = Split(m_pdf.GetPageText(3), vbCrLf)
    For lTmp = 0 To UBound(aWords)
        DoEvents
        If InStr(1, aWords(lTmp), sSearchText, vbTextCompare) Then
            Debug.Print Mid$(aWords(lTmp), InStr(1, aWords(lTmp), "#"))
            aParams = Split(Mid$(aWords(lTmp), InStr(1, aWords(lTmp), "#")), ",")
            dLeft = CDbl(aParams(2))
            dTop = CDbl(aParams(3)) + CDbl(aParams(1))
            dWidth = CDbl(aParams(4)) - CDbl(aParams(2))
            dHeight = CDbl(aParams(7)) - CDbl(aParams(3))
            sLink = sLink
            Debug.Print dLeft, dTop, dWidth, dHeight, sLink
            m_pdf.AddLinkToWeb dLeft, dTop, dWidth, dHeight, sLink, 0
        End If
    Next
 
End Function
------------------------------------------

I just loop through the each page with each phrase I want to link and call this function.
If you have a big list of phrases/links and the PDF has alot of pages it can take a good while but it does work.

When I'm done I just call "m_pdf.SaveToFile" to save it to a new file.

-jjohnston



Edited by jjohnston - 26 Jun 07 at 12:21AM
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 26 Jun 07 at 1:54AM
Hi!
Yes... Your solution will works. I had understand that you want to dig directly into the code to change or implement these things... and this won't work.
The functions you're asking for are:
AddLinkToFile
AddLinkToPage
AddLinkToWeb
...the first functions described in the documentation on page 3...4 ;-)

Best regards,
Ingo

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store