[reportlab-users] External hyperlinks in SVG output

Peter peter at maubp.freeserve.co.uk
Tue Feb 24 11:41:30 EST 2009


On Mon, Feb 16, 2009 at 5:23 PM, Peter <peter at maubp.freeserve.co.uk> wrote:

> I see this is in your SVN repository now :)


I've attached a patch against the current SVN version of renderSVG.py
to support making links on closed SVG paths. Without this only the
simplest of vector shapes had working links (rectangles, polygons,
circles, etc), but by supporting closed paths this lets the user
create any complicated shape - and have it linkable :)

At the end of the email is an example of how this might get used.

Peter

--------------
from reportlab.graphics import renderPS, renderPDF, renderSVG, renderPM
from reportlab.lib.units import cm
from reportlab.graphics import shapes
from reportlab.lib import colors

width=10*cm
height=2*cm

#Create fairly simple drawing object,
drawing=shapes.Drawing(width, height)

p=shapes.ArcPath(strokeColor=colors.darkgreen,
fillColor=colors.green,
hrefURL="http://en.wikipedia.org/wiki/Vector_path",
hrefTitle="This big letter C is actually a closed
vector path.",
strokewidth=0)
p.addArc(1*cm, 1*cm, 0.8*cm, 20, 340, moveTo=True)
p.addArc(1*cm, 1*cm, 0.9*cm, 20, 340, reverse=True)
p.closePath()
drawing.add(p)

drawing.add(shapes.Rect(2.25*cm, 0.1*cm, 1.5*cm, 0.8*cm, rx=0.25*cm, ry=0.25*cm,

hrefURL="http://en.wikipedia.org/wiki/Rounded_rectangle",
hrefTitle="Rounded Rectangle",
strokeColor=colors.red,
fillColor=colors.yellow))

drawing.add(shapes.String(1*cm, 1*cm, "Hello World!",
hrefURL="http://en.wikipedia.org/wiki/Hello_world",
hrefTitle="Why 'Hello World'?",
fillColor=colors.darkgreen))
drawing.add(shapes.Rect(4.5*cm, 0.5*cm, 5*cm, 1*cm,
hrefURL="http://en.wikipedia.org/wiki/Rectangle",
hrefTitle="Wikipedia page on rectangles",
strokeColor=colors.blue,
fillColor=colors.red))
drawing.add(shapes.Ellipse(7*cm, 1*cm, 2*cm, 0.95*cm,
hrefURL="http://en.wikipedia.org/wiki/Ellipse",
strokeColor=colors.black,
fillColor=colors.yellow))
drawing.add(shapes.Circle(7*cm, 1*cm, 0.9*cm,
hrefURL="http://en.wikipedia.org/wiki/Circle",
strokeColor=colors.black,
fillColor=colors.brown))
drawing.add(shapes.Ellipse(7*cm, 1*cm, 0.5*cm, 0.9*cm,
hrefTitle="Tooltip with no link?",
strokeColor=colors.black,
fillColor=colors.black))
drawing.add(shapes.Polygon([4.5*cm, 1.25*cm, 5*cm, 0.1*cm, 4*cm, 0.1*cm],
hrefURL="http://en.wikipedia.org/wiki/Polygon",
hrefTitle="This triangle is a simple polygon.",
strokeColor=colors.darkgreen,
fillColor=colors.green))

renderPDF.drawToFile(drawing, "hello.pdf")
renderPS.drawToFile(drawing, "hello.ps")
renderSVG.drawToFile(drawing, "hello.svg")
renderPM.drawToFile(drawing, "hello.png", "PNG")

print "-" * 50
print renderSVG.drawToString(drawing)
print "-" * 50
print "Done"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: svg_link_closed_paths.patch
Type: application/octet-stream
Size: 1425 bytes
Desc: not available
Url : <http://two.pairlist.net/pipermail/reportlab-users/attachments/20090224/2a4db1bf/attachment.obj>


More information about the reportlab-users mailing list