本文整理汇总了Python中reportlab.platypus.SimpleDocTemplate.title方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleDocTemplate.title方法的具体用法?Python SimpleDocTemplate.title怎么用?Python SimpleDocTemplate.title使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.platypus.SimpleDocTemplate
的用法示例。
在下文中一共展示了SimpleDocTemplate.title方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_agenda
# 需要导入模块: from reportlab.platypus import SimpleDocTemplate [as 别名]
# 或者: from reportlab.platypus.SimpleDocTemplate import title [as 别名]
def print_agenda(request):
response = HttpResponse(mimetype='application/pdf')
filename = u'filename=%s.pdf;' % _("Agenda")
response['Content-Disposition'] = filename.encode('utf-8')
doc = SimpleDocTemplate(response)
story = [Spacer(1,3*cm)]
doc.title = _("Agenda")
# print item list
items = children_list(Item.objects.filter(parent=None).order_by('weight'))
for item in items:
if item.hidden is False:
# print all items"
if item.parents:
space = ""
counter = 0
for p in item.parents:
if counter != 0:
space += " "
counter += 1
story.append(Paragraph(space+item.title, stylesheet['Subitem']))
else:
story.append(Paragraph(item.title, stylesheet['Item']))
doc.build(story, onFirstPage=firstPage, onLaterPages=laterPages)
return response
示例2: print_assignment
# 需要导入模块: from reportlab.platypus import SimpleDocTemplate [as 别名]
# 或者: from reportlab.platypus.SimpleDocTemplate import title [as 别名]
def print_assignment(request, assignment_id=None):
response = HttpResponse(mimetype='application/pdf')
filename = u'filename=%s.pdf;' % _("Elections")
response['Content-Disposition'] = filename.encode('utf-8')
doc = SimpleDocTemplate(response)
doc.title = None
story = []
if assignment_id is None: #print all applications
title = config_get("assignment_pdf_title")
story.append(Paragraph(title, stylesheet['Heading1']))
preamble = config_get("assignment_pdf_preamble")
if preamble:
story.append(Paragraph("%s" % preamble.replace('\r\n','<br/>'), stylesheet['Paragraph']))
story.append(Spacer(0,0.75*cm))
# List of assignments
for assignment in Assignment.objects.order_by('name'):
story.append(Paragraph(assignment.name, stylesheet['Heading3']))
# Assignment details (each assignment on single page)
for assignment in Assignment.objects.order_by('name'):
story.append(PageBreak())
story = get_assignment(assignment, story)
else: # print selected assignment
assignment = Assignment.objects.get(id=assignment_id)
filename = u'filename=%s-%s.pdf;' % (_("Assignment"), assignment.name.replace(' ','_'))
response['Content-Disposition'] = filename.encode('utf-8')
story = get_assignment(assignment, story)
doc.build(story, onFirstPage=firstPage, onLaterPages=firstPage)
return response
示例3: current_week_pdf
# 需要导入模块: from reportlab.platypus import SimpleDocTemplate [as 别名]
# 或者: from reportlab.platypus.SimpleDocTemplate import title [as 别名]
def current_week_pdf(self):
"""Lucky numbers for current or next week in pdf format."""
change_hour = 15
numbers = LuckyNumber.current_week(change_hour)
if len(numbers) == 0:
return redirect(url('lucky_week'))
# Register fonts
ubuntu_r = resource_filename(Requirement.parse("SIS"), "resources/Ubuntu-R.ttf")
ubuntu_b = resource_filename(Requirement.parse("SIS"), "resources/Ubuntu-B.ttf")
pdfmetrics.registerFont(TTFont('Ubuntu', ubuntu_r))
pdfmetrics.registerFont(TTFont('Ubuntu Bold', ubuntu_b))
numbers_pdf = StringIO.StringIO()
doc = SimpleDocTemplate(numbers_pdf, pagesize=A4, topMargin=A4[1]*0.26)
doc.author = 'SIS'
doc.title = 'Szczęśliwy numerek'
data = []
for number in numbers:
date = number.date.strftime("%d.%m.%y")
data.append(('{0} -'.format(date), str(number.number)))
table = Table(data)
table.setStyle(TableStyle([
('FONT', (0, 0), (0, -1), 'Ubuntu', 80),
('FONT', (1, 0), (1, -1), 'Ubuntu Bold', 80),
]))
def header_and_footer(canvas, document):
canvas.saveState()
size = document.pagesize
center = size[0] / 2
canvas.setFont('Ubuntu', 80)
canvas.drawCentredString(center,
size[1] - document.topMargin / 2, "SZCZĘŚLIWY")
canvas.drawCentredString(center, size[1] - document.topMargin + 20, 'NUMEREK')
canvas.setFont('Ubuntu', 15)
canvas.drawRightString(size[0] - document.rightMargin,
document.bottomMargin - 20, "Samorząd Uczniowski")
canvas.restoreState()
doc.build([table], onFirstPage=header_and_footer,
onLaterPages=header_and_footer)
response.headers['Content-type'] = 'application/pdf'
return numbers_pdf.getvalue()
示例4: create
# 需要导入模块: from reportlab.platypus import SimpleDocTemplate [as 别名]
# 或者: from reportlab.platypus.SimpleDocTemplate import title [as 别名]
def create(nodenick):
buffer = StringIO()
doc = SimpleDocTemplate(buffer)
doc.author = "dinemo"
doc.subject = "Network monitoring report"
doc.title = "Network monitoring report"
Story = []
# img = Image("dinemomaster/static/images/logo.jpg", 214, 50)
img = Image("dinemomaster/static/images/logo.jpg", 107, 25)
img.hAlign='RIGHT'
Story.append(img)
Story.append(Spacer(1,7 * cm))
style = styles["title"]
style.textColor = "darkblue"
style.fontSize = 20
Story.append(Paragraph("Network moritoring report", style))
Story.append(Spacer(1,0.5 * cm))
style.fontSize = 14
Story.append(Paragraph("Generated on %s" % strftime("%d %h %Y"), style))
if nodenick:
style.fontSize = 16
Story.append(Spacer(1,1 * cm))
Story.append(Paragraph(" \"%s\" node network metrics""" % nodenick, style))
style = styles["Normal"]
style.textColor = "black"
Story.append(PageBreak())
for i in range(100):
bogustext = ("Paragraph number %s. " % i) *20
p = Paragraph(bogustext, style)
Story.append(p)
Story.append(Spacer(1,0.2*cm))
doc.build(Story, onLaterPages= _later_page)
pdf = buffer.getvalue()
buffer.close()
return pdf
示例5: print_userlist
# 需要导入模块: from reportlab.platypus import SimpleDocTemplate [as 别名]
# 或者: from reportlab.platypus.SimpleDocTemplate import title [as 别名]
def print_userlist(request):
response = HttpResponse(mimetype='application/pdf')
filename = u'filename=%s.pdf;' % _("Participant-list")
response['Content-Disposition'] = filename.encode('utf-8')
doc = SimpleDocTemplate(response)
story = [Spacer(1,2*cm)]
doc.title = _("List of Participants")
# Table
data= [['#', _('Last Name'), _('First Name'), _('Group'), _('Type'), _('Committee')]]
sort = 'last_name'
counter = 0
for user in User.objects.all().order_by(sort):
try:
counter += 1
user.get_profile()
data.append([counter,
Paragraph(user.last_name, stylesheet['Tablecell']),
Paragraph(user.first_name, stylesheet['Tablecell']),
Paragraph(user.profile.group, stylesheet['Tablecell']),
Paragraph(user.profile.get_type_display(), stylesheet['Tablecell']),
Paragraph(user.profile.committee, stylesheet['Tablecell']),
])
except Profile.DoesNotExist:
counter -= 1
pass
t=LongTable(data,
style=[
('VALIGN',(0,0),(-1,-1), 'TOP'),
('LINEABOVE',(0,0),(-1,0),2,colors.black),
('LINEABOVE',(0,1),(-1,1),1,colors.black),
('LINEBELOW',(0,-1),(-1,-1),2,colors.black),
('ROWBACKGROUNDS', (0, 1), (-1, -1), (colors.white, (.9, .9, .9))),
])
t._argW[0]=0.75*cm
story.append(t)
doc.build(story, onFirstPage=firstPage, onLaterPages=laterPages)
return response
示例6: print_application
# 需要导入模块: from reportlab.platypus import SimpleDocTemplate [as 别名]
# 或者: from reportlab.platypus.SimpleDocTemplate import title [as 别名]
def print_application(request, application_id=None):
response = HttpResponse(mimetype='application/pdf')
filename = u'filename=%s.pdf;' % _("Applications")
response['Content-Disposition'] = filename.encode('utf-8')
doc = SimpleDocTemplate(response)
doc.title = None
story = []
if application_id is None: #print all applications
title = config_get("application_pdf_title")
story.append(Paragraph(title, stylesheet['Heading1']))
preamble = config_get("application_pdf_preamble")
if preamble:
story.append(Paragraph("%s" % preamble.replace('\r\n','<br/>'), stylesheet['Paragraph']))
story.append(Spacer(0,0.75*cm))
# List of applications
for application in Application.objects.order_by('number'):
if application.number:
story.append(Paragraph(_("Application No.")+" %s: %s" % (application.number, application.title), stylesheet['Heading3']))
else:
story.append(Paragraph(_("Application No.")+" : %s" % (application.title), stylesheet['Heading3']))
# Applications details (each application on single page)
for application in Application.objects.order_by('number'):
story.append(PageBreak())
story = get_application(application, story)
else: # print selected application
application = Application.objects.get(id=application_id)
if application.number:
number = application.number
else:
number = ""
filename = u'filename=%s%s.pdf;' % (_("Application"), str(number))
response['Content-Disposition'] = filename.encode('utf-8')
story = get_application(application, story)
doc.build(story, onFirstPage=firstPage, onLaterPages=firstPage)
return response
示例7: run
# 需要导入模块: from reportlab.platypus import SimpleDocTemplate [as 别名]
# 或者: from reportlab.platypus.SimpleDocTemplate import title [as 别名]
def run(self):
linkbundle = self.link.split('/')[-3:][:2]
if linkbundle[0] == interface.series:
linkbundle[0] = '/'
else:
linkbundle[0] = '/'+linkbundle[0]+'/'
##Check if not downloaded already.
try:
chapters = os.listdir(interface.series)
except:
chapters = []
if linkbundle[1]+'.pdf' in chapters and not interface.force:
interface.completed = interface.completed+1.0/interface.seriesLen
idle_add(self.update_status, interface.completed, 'Chapter '+linkbundle[1].strip('c')+' was found downloaded.')
return True
##Completed that chapter!
idle_add(self.update_status, None, 'Start reading chapter '+linkbundle[1].strip('c'))
for page in range(1, 1000):
url = 'http://www.mangafox.com/manga/'+interface.series+linkbundle[0]+linkbundle[1]+'/'+str(page)+'.html'
request = urllib2.Request(url, interface.urllib, interface.headers)
try:
content = urllib2.urlopen(request).read()
except:
continue
try:
image=interface.regex.search(content).group(0)
if not image in self.images:
self.images.append(image)
else:
break ##Chapter END
except:
print 'Could not get image for chapter '+linkbundle[1]+' page '+str(page)
break ##Could not get image!
interface.completed = interface.completed+(0.25/interface.seriesLen)
idle_add(self.update_status, interface.completed, 'Downloading chapter '+linkbundle[1].strip('c'))
###
##Downloading images.
###
chapterLen = len(self.images)
if chapterLen < 2:
interface.completed = interface.completed+(0.75/interface.seriesLen)
idle_add(self.update_status, interface.completed, 'Done chapter '+linkbundle[1].strip('c'))
return True
try:
os.mkdir(interface.series)
except:
pass
try:
os.mkdir(os.path.join(interface.series, linkbundle[1]))
except:
pass
for image in self.images:
imagename=image.split('/')[-1]
img = open(os.path.join(interface.series, linkbundle[1], imagename), 'w')
img.write(urllib2.urlopen(image).read())
img.close()
interface.completed = interface.completed+(0.5/interface.seriesLen/chapterLen)
idle_add(self.update_status, interface.completed, None)
###
##Making PDF
###
c=SimpleDocTemplate(os.path.join(interface.series, linkbundle[1]+'.pdf'),
pagesize=interface.psize,
rightMargin=0,
leftMargin=0,
topMargin=0,
bottomMargin=0)
Story=[]
maxh = interface.psize[1]-20
maxw = interface.psize[0]-30
title=' '.join(interface.series.split('_'))
c.title=title+' '+linkbundle[1]
c.author=interface.author
directory=os.path.join(interface.series, linkbundle[1])
images=sorted(os.listdir(directory))
for image in images:
img = PImage.open(os.path.join(directory, image))
width, height = img.size
img = img.crop(( 0, 0, width, height-40))
img.save(os.path.join(directory, image))
img = PImage.open(os.path.join(directory, image))
width, height = img.size
if width/maxw>height/maxh:
height=height/(width/maxw)
width=maxw
if width>height:
img = img.rotate(90)
img.save(os.path.join(directory, image))
width, height = img.size
if width/maxw>height/maxh:
height=height/(width/maxw)
width=maxw
else:
width=width/(height/maxh)
height=maxh
else:
width=width/(height/maxh)
height=maxh
im = Image(os.path.join(directory, image), width, height)
Story.append(im)
#.........这里部分代码省略.........
示例8: generatepdf
# 需要导入模块: from reportlab.platypus import SimpleDocTemplate [as 别名]
# 或者: from reportlab.platypus.SimpleDocTemplate import title [as 别名]
def generatepdf():
'''This method generates summary pdf from the results of result processor.
'''
global result
global exam
doc = SimpleDocTemplate("report.pdf", pagesize=A4,
rightMargin=72, leftMargin=72,
topMargin=50, bottomMargin=30)
Story = []
doc.title = "Exam Result Summary"
# Defining different text styles to be used in PDF
styles = getSampleStyleSheet()
styles.add(ParagraphStyle(name='Center1', alignment=1, fontSize=18))
styles.add(ParagraphStyle(name='Center2', alignment=1, fontSize=13))
styles.add(ParagraphStyle(name='Normal2', bulletIndent=20))
styles.add(ParagraphStyle(name='Normal3', fontSize=12))
for college in result:
for branch in result[college]:
# PDF Generation begins
Story.append(Paragraph(college, styles["Center1"]))
Story.append(Spacer(1, 0.25 * inch))
Story.append(Paragraph(exam, styles["Center2"]))
Story.append(Spacer(1, 12))
numberofstudents = len(result[college][branch].itervalues().next())
Story.append(Paragraph(branch, styles["Center2"]))
Story.append(Spacer(1, 0.25 * inch))
Story.append(Paragraph("Total Number of Students : %d" %
numberofstudents, styles["Normal2"]))
Story.append(Spacer(1, 12))
for subject in result[college][branch]:
marklist = [int(result[college][branch][subject][x][0])
for x in result[college][branch][subject]]
average = statistics.mean(marklist) # Calculating mean
stdev = statistics.pstdev(marklist) # Calculating standard deviation
passlist = {x for x in result[college][branch][
subject] if 'P' in result[college][branch][subject][x]}
faillist = {x for x in result[college][branch][
subject] if 'F' in result[college][branch][subject][x]}
absentlist = {x for x in result[college][branch][
subject] if 'AB' in result[college][branch][subject][x]}
passcount = len(passlist)
failcount = len(faillist)
absentcount = len(absentlist)
percentage = float(passcount) / numberofstudents
subjectname = "<b>%s</b>" % subject
passed = "<bullet>•</bullet>Students Passed : %d" \
% passcount
failed = " <bullet>•</bullet>Students Failed : %d" \
% failcount
absent = " <bullet>•</bullet>Students Absent : %d" \
% absentcount
percentage = " <bullet>•</bullet>Pass Percentage : %.2f"\
% percentage
average = " <bullet>•</bullet>Average Marks : %.2f" \
% average
stdev = "<bullet>•</bullet>Standard Deviation : %.2f" \
% stdev
Story.append(Paragraph(subjectname, styles["Normal"]))
Story.append(Spacer(1, 12))
Story.append(Paragraph(passed, styles["Normal2"]))
Story.append(Spacer(1, 12))
Story.append(Paragraph(failed, styles["Normal2"]))
Story.append(Spacer(1, 12))
Story.append(Paragraph(absent, styles["Normal2"]))
Story.append(Spacer(1, 12))
Story.append(Paragraph(percentage, styles["Normal2"]))
Story.append(Spacer(1, 12))
Story.append(Paragraph(average, styles["Normal2"]))
Story.append(Spacer(1, 12))
Story.append(Paragraph(stdev, styles["Normal2"]))
Story.append(Spacer(1, 12))
Story.append(PageBreak()) # Each department on new page
doc.build(Story)