appended authors paragraph

master
simon 5 years ago
parent 9ffe826db4
commit 32907668d9

@ -1,19 +1,47 @@
from reportlab.lib.pagesizes import letter, A4
from reportlab.lib.pagesizes import *
from reportlab.pdfgen import canvas
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from calibrestekje import Book, Publisher, init_session
doc = SimpleDocTemplate("text.pdf", pagesize=A4,
rightMargin=72, leftMargin=72,
topMargin=72, bottomMargin=18)
pagewidth, pageheight = landscape(A6)
doc = SimpleDocTemplate("text.pdf", pagesize=landscape(A6),
rightMargin=18, leftMargin=18,
topMargin=0, bottomMargin=18)
content = []
styles = getSampleStyleSheet()
for i in range(10):
p = Paragraph('<font size=12>{}</font>'.format(i), styles["Normal"])
session = init_session("sqlite:///metadata.db")
for book in session.query(Book).all():
print (book.title)
print (book.authors)
# c.drawString(10,pageheight-10, book.title)
# c.showPage()
# create a paragraph and append content to it - e.g. book.title, book.authors etc
p = Paragraph('<font size=12>{}</font>'.format(book.title), styles["Italic"])
content.append(p)
# content.append(PageBreak())
content.append(Spacer(1, 12))
#import ipdb; ipdb.set_trace()
format_string = '<font size=12>{}</font>'
all_authors = [author.name for author in book.authors]
glued_together = format_string.format(", ".join(all_authors))
#if all_authors==['John Markoff']:
# import ipdb; ipdb.set_trace()
p = Paragraph(glued_together, styles["Normal"])
content.append(p)
content.append(PageBreak())
content.append(Spacer(1, 12))
doc.build(content)
doc.build(content)
Loading…
Cancel
Save