[Biopython-dev] [Bug 2718] Bio.Graphics and output file formats (PDF, EPS, SVG, and bitmaps)

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Tue Dec 23 12:55:11 UTC 2008


http://bugzilla.open-bio.org/show_bug.cgi?id=2718





------- Comment #1 from biopython-bugzilla at maubp.freeserve.co.uk  2008-12-23 07:55 EST -------
Example script showing the reportlab render modules producing output given a
filename, handle, or via a string:

from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.units import cm
from reportlab.graphics import renderPS, renderPDF, renderPM
from reportlab.graphics.shapes import Drawing, String

width = 10*cm
height = 2*cm

print "Using canvas directly (PDF only)..."
c = Canvas("hello1.pdf", pagesize=(width, height))
c.drawString(1*cm, 1*cm, "Hello World!")
c.showPage()
c.save()

#Create very simple drawing object,
drawing = Drawing(width, height)
drawing.add(String(1*cm, 1*cm, "Hello World!"))

print "Using filenames..."
renderPDF.drawToFile(drawing, "hello2.pdf")
renderPM.drawToFile(drawing, "hello2.png", "PNG")

print "Using handles..."
handle = open("hello3.pdf","w")
renderPDF.drawToFile(drawing, handle)
handle.close()
handle = open("hello3.ps","w")
renderPS.drawToFile(drawing, handle)
handle.close()
handle = open("hello3.png","w")
renderPM.drawToFile(drawing, handle, "PNG")
handle.close()

print "Using strings..."
handle = open("hello4.pdf","w")
handle.write(renderPDF.drawToString(drawing))
handle.close()
handle = open("hello4.ps","w")
handle.write(renderPS.drawToString(drawing))
handle.close()
handle = open("hello4.png","w")
handle.write(renderPM.drawToString(drawing, "PNG"))
handle.close()

print "Done"


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the Biopython-dev mailing list