I have done something similar using both what was suggested by @nmpeterson and @Jason, here is a basic Platypus (ReportLab) sample with a table:
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.rl_config import defaultPageSize
from reportlab.lib.units import inch
from reportlab.lib import colors
import arcpy
PAGE_HEIGHT=defaultPageSize[1]
PAGE_WIDTH=defaultPageSize[0]
styles = getSampleStyleSheet()
Title = "Table"
pageinfo = "Table example"
def myFirstPage(canvas, doc):
canvas.saveState()
canvas.setFont('Times-Bold',16)
canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT-108, Title)
canvas.setFont('Times-Roman',9)
canvas.drawString(inch, 0.75 * inch,"First Page / %s" % pageinfo)
canvas.restoreState()
def myLaterPages(canvas, doc):
canvas.saveState()
canvas.setFont('Times-Roman', 9)
canvas.drawString(inch, 0.75 * inch,"Page %d %s" % (doc.page, pageinfo))
canvas.restoreState()
def go():
# Convert your table to an array with whatever method works best for you
dataDic = tableToDic(tablePath)
columnName = dataDic.keys()
dataArray = dicToArray(dataDic)
# Create the ReportLab document
doc = SimpleDocTemplate("helloTable.pdf")
# Create the table element with whatever parameters suit you best
Story = [Spacer(1,2*inch)]
style = styles["Normal"]
dataArray = tableArray
width = len(columnNames)
dataArray.insert(0, columnNames)
cellWidth = [7 * inch / width for i in columnNames]
table = Table(dataArray, cellWidth)
table.setStyle(TableStyle([
('BACKGROUND', (0, 0), (-1, 0), colors.grey),
('GRID',(0,0),(-1,-1),0.5,colors.black),
]))
# Generate the document
Story.append(table)
doc.build(Story, onFirstPage=myFirstPage, onLaterPages=myLaterPages)
if __name__ == "__main__":
go()
About the "convert the table to an array" part, it depends on what ArcGIS version you are using. I have discussed a similar issue on the thread : Is it a bad idea to convert a File Geodatabase table to a dictionary? If you are using ArcGIS 10.1+, you can use nmpeterson's make_attribute_dict function and customize it to make an array instead of a dictionary. If you're using an older version, I can give you some other pieces of code to convert your tables to a dictionary/array. If you use the table to dictionary function such as, you can also use the following line to convert the dictionary to an array:
tableArray = [tuple(tableDic[key]) for key in tableDic.iterkeys()]
Of course you can always turn things around to work directly with arrays.