[reportlab-users] links to other pdfs ...

Larry Bates reportlab-users@reportlab.com
Thu, 24 Jun 2004 08:38:50 -0500

Below is some code that allows you to imbed any http://
link in .PDF file.  This could point to .PDF (either
locally with file:// or remotely with http://.

Hope it helps.
Larry Bates
Syscon, Inc.

def URLLinkAbsolute0(canv, url, rect, border=[0,0,0], contents="click here"):
    url is url to link to, rect is [x1,y1,x2,y2]
    where (x1,y1) is lower left and (x2,y2) upper right corners
    of the annotation rectangle respectively.
    from reportlab.pdfbase.pdfdoc import PDFDictionary, PDFName, PDFArray,
    ann = PDFDictionary()
    ann["Type"] = PDFName("Annot")
    ann["Subtype"] = PDFName("Link")
    ann["Rect"] = PDFArray(rect) # the whole page for testing
    ann["Border"] = PDFArray(border)
    ann["Contents"] = PDFString(contents)
    A = PDFDictionary()
    #A["Type"] = PDFName("Action") # not needed?
    ann["H"] = PDFName("I") # invert
    A["S"] = PDFName("URI")
    A["URI"] = PDFString(url)
    ann["A"] = A

def test():
    from reportlab.pdfgen import canvas
    fn = "c:\\temp\\urltest.pdf"
    c = canvas.Canvas(fn)
    URLLinkAbsolute0(c, "http://www.alsde.edu", [72,638,256,652])
    c.drawString(73,639, "http://www.alsde.edu")
    print "wrote", fn

if __name__=="__main__":

-----Original Message-----
From: reportlab-users-admin@reportlab.com
[mailto:reportlab-users-admin@reportlab.com]On Behalf Of
Sent: Thursday, June 24, 2004 12:07 AM
To: reportlab-users@reportlab.com
Subject: reportlab-users digest, Vol 2 #142 - 1 msg

Send reportlab-users mailing list submissions to

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to

You can reach the person managing the list at

When replying, please edit your Subject line so it is more specific
than "Re: Contents of reportlab-users digest..."

Today's Topics:

   1. links to other pdfs ... (Jesse David Andrews)


Message: 1
From: "Jesse David Andrews" <Jesse@uky.edu>
To: reportlab-users@reportlab.com
Date: Wed, 23 Jun 2004 02:05:18 -0400
Subject: [reportlab-users] links to other pdfs ...
Reply-To: reportlab-users@reportlab.com


I am  just starting to get to know reportlab, and it has been very good so =
far.  I am just having an issue creating "links" that either switch the c=
urrent document or open another document in another adobe window.  Maybe =
I am not reading the manual correctly, but it appears that this functiona=
lity isn't there yet.  I don't really know PDF specs, but have programmed=
 python and postscript before, so I might be able to impliment it if it c=
urrently doesn't exist (although hints about how to do it would be greatl=
y appreciated)



reportlab-users mailing list

End of reportlab-users Digest