Print Page | Close Window

Search a PDF and add links to text strings

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=748
Printed Date: 05 May 24 at 6:51AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Search a PDF and add links to text strings
Posted By: jjohnston
Subject: Search a PDF and add links to text strings
Date 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...



Replies:
Posted By: Ingo
Date 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



Posted By: jjohnston
Date 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


Posted By: jjohnston
Date 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



Posted By: Ingo
Date 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




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk