当前位置: 首页>>代码示例>>Python>>正文


Python BaseDocTemplate.addPageTemplates方法代码示例

本文整理汇总了Python中reportlab.platypus.BaseDocTemplate.addPageTemplates方法的典型用法代码示例。如果您正苦于以下问题:Python BaseDocTemplate.addPageTemplates方法的具体用法?Python BaseDocTemplate.addPageTemplates怎么用?Python BaseDocTemplate.addPageTemplates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reportlab.platypus.BaseDocTemplate的用法示例。


在下文中一共展示了BaseDocTemplate.addPageTemplates方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ReporteVertical

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
class ReporteVertical(object):
	"""docstring for ReporteVertical"""
	def __init__(self, nombreReporteP, directorioArchivoP, operadorP):
		super(ReporteVertical, self).__init__()
		self.PAGE_HEIGHT = letter[1]
		self.PAGE_WIDTH = letter[0]
		self.story = []
		self.styles = getSampleStyleSheet()
		self.nombreReporte = str(nombreReporteP)
		self.dirArchivo = str(directorioArchivoP)
		self.tipoArchivo = ".pdf"
		global operador
		global imagenes
		operador = str(operadorP)
		imagenes = ['static/image/universidad.jpg', 'static/image/alcaldia.png']

	def inicializarReporte(self, nombreReporteP):
		self.doc = BaseDocTemplate(nombreReporteP, pagesize=letter)

	def contenidoFrame(self):
		self.contenidoFrame = Frame(self.doc.leftMargin, (self.doc.height - self.doc.topMargin), self.doc.width, self.doc.height / 6, showBoundary=1)

	def constructorPaginas(self):
		self.doc.addPageTemplates([PageTemplate(id='reporte', frames=self.contenidoFrame, onPage =encabezado, onPageEnd=piePagina)])

	def crearReporteVertical(self):
		try:
			self.inicializarReporte(os.path.join(self.dirArchivo, self.nombreReporte + self.tipoArchivo))
			self.contenidoFrame()
			self.constructorPaginas()
			self.story.append(Paragraph("El viaje del navegante. Blog de Python", self.styles['Normal']))
			self.doc.build(self.story)
			os.system(os.path.join(self.dirArchivo, self.nombreReporte + self.tipoArchivo))
		except Exception, e:
			print e
开发者ID:mfreyeso,项目名称:SIPREM,代码行数:37,代码来源:reporteVertical.py

示例2: build_pdf

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
def build_pdf(filename):
    doc = BaseDocTemplate(filename)
    
    column_gap = 1 * cm
    
    doc.addPageTemplates(
        [
            PageTemplate(
                frames=[
                    Frame(
                        doc.leftMargin,
                        doc.bottomMargin,
                        doc.width / 2,
                        doc.height,
                        id='left',
                        rightPadding=column_gap / 2,
                        showBoundary=0  # set to 1 for debugging
                    ),
                    Frame(
                        doc.leftMargin + doc.width / 2,
                        doc.bottomMargin,
                        doc.width / 2,
                        doc.height,
                        id='right',
                        leftPadding=column_gap / 2,
                        showBoundary=0
                    ),
                ]
            ),
        ]
    )
    flowables = [
        Paragraph('word ' * 700, ParagraphStyle('default')),
    ]
    doc.build(flowables)
开发者ID:pythonpatterns,项目名称:patterns,代码行数:37,代码来源:p0149.py

示例3: fill

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
    def fill(self, fname, pagesize, events, topspace, bottomspace, margins):
        tf = tempfile.NamedTemporaryFile(delete=False)
        pagesize = (pagesize[0] / 2 - 6, pagesize[1])
        doc = BaseDocTemplate(tf.name, pagesize=pagesize, leftMargin=margins, bottomMargin=bottomspace, rightMargin=margins, topMargin=topspace)
        column = Frame(doc.leftMargin+6, doc.bottomMargin+0.5*inch, doc.width-6, 3.3*inch)
        rsvp = Frame(doc.leftMargin+6, doc.bottomMargin, doc.width-6, 0.5*inch)
        doc.addPageTemplates(PageTemplate(frames=[rsvp, column]))

        # render one side
        story = []
        story.append(Paragraph("Please RSVP at map.berniesanders.com", styles["default"]))
        story.append(FrameBreak())
        for e in events:
            story.append(Event(e).render())
        doc.build(story)

        # now duplicate for 2-up
        src = PdfFileReader(open(tf.name, "rb"))
        out = PdfFileWriter()
        lhs = src.getPage(0)
        lhs.mergeTranslatedPage(lhs, lhs.mediaBox.getUpperRight_x(), 0, True)
        out.addPage(lhs)
        with open(fname.name, "wb") as outfile:
            out.write(outfile)
        os.remove(tf.name)
开发者ID:12foo,项目名称:event-flyer-factory,代码行数:27,代码来源:layouts.py

示例4: create_pdf

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
def create_pdf(data):
	report_header='./static/images/report-header.jpg'
	other_header='./static/images/report-header2.jpg'
	today=data[0]
	pname=data[1]
	orgname=data[2]
	mission=data[3]
	product=data[4]
	puser=data[5]
	inputs=data[6]
	outputs=data[7]
	controls=data[8]
	plots=data[9]
	regs=data[10]
	reporttext = []
	#File Name
	pdfname="hello"+pname+"_"+today
	doc=BaseDocTemplate(pdfname,pagesize=letter)
	frame=Frame(doc.leftMargin,doc.bottomMargin,doc.width,doc.height,id='normal')
	template=PageTemplate(id='test',frames=frame,onPage=footer)
	doc.addPageTemplates([template])
	styles = getSampleStyleSheet()
	methods="In keeping with the ReadyMade tenet to keep the analysis simple, we look for one key outcome variable that is highly correlated with the other available outcome variables "
	reporttext.append(Paragraph(methods,styles['Normal']))
	doc.build(metext)
	return pdfname
开发者ID:priya-I,项目名称:ReadyMade,代码行数:28,代码来源:test.py

示例5: create_pdf

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
def create_pdf(togen, template_page, pos, dat):
    "Create the pdf, stream api"
    document = BaseDocTemplate(togen)
    page = MyPage(template_page, name='background') 
    document.addPageTemplates([page])
    elements = [NextPageTemplate('background')]
    # may add flowables to element here
    
    # add absolute content
    for posname in dat:
        if posname.startswith("_"): # ignore extra info
            continue
        if posname not in pos:
            raise Exception("%s does not have a position" % posname)
        tup = pos[posname]
        x, y = tup[0], tup[1]
        width = tup[2] if len(tup)>2 else PAGE_WIDTH
        style = tup[3] if len(tup)>3 else DEFAULT_STYLE
        data = dat[posname]
        if type(data) in (str, unicode):
            page.addAbsParagraph(data, x, y, width, style)
        else:
            page.addAbsPrimitive(data, x, y, width) # don't need no style
    # create page
    document.multiBuild(elements)
开发者ID:hesrerem,项目名称:pdffill,代码行数:27,代码来源:pdffill.py

示例6: makeForm

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
def makeForm():
    ''' Make PDF of MyPidge app form. '''
    posts = []
    pageWidth, pageHeight = A4
    formPages = (
    FormFront(None),
    FormFront(None),
    FormFront(None),
    FormFront(None),
    FormBack(None),
    FormBack(None),
    FormBack(None),
    FormBack(None),
    )
    for (offset, frame) in enumerate(formPages):
        posts.append(frame.makeFrame())
        if len(formPages)==(offset+1):
            # Break page at end of a PocketPidge
            # But need to do this twice if on an odd page
            posts.append(PageBreak())
        else:
            posts.append(FrameBreak())
        
    # Build File
    document = BaseDocTemplate("form.pdf", pagesize=A4)
    template = PageTemplate(frames=createFrames(pageWidth, pageHeight, 2, 2))
    document.addPageTemplates(template)
    document.build(posts)
开发者ID:fergusrossferrier,项目名称:mypidge.com,代码行数:30,代码来源:PocketPidge.py

示例7: seatingChartByStudent

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
def seatingChartByStudent(request, id):
    mealTime = models.MealTime.objects.get(pk=id)

    allStudents = set(mealTime.allStudents())
    seenStudents = set()

    data = []

    for tableAssignment in mealTime.tableassignment_set.all():
        table = tableAssignment.table
        student = tableAssignment.student

        data.append((student.first_name, student.last_name, table.description))

        seenStudents.add(student)

    leftovers = [(s.first_name, s.last_name) for s in (allStudents - seenStudents)]
    leftovers.sort(key=lambda s: (s[1], s[0]))
    data.sort(key=lambda s: (s[1], s[0]))
        
    normal = getSampleStyleSheet()["Normal"]
    heading = getSampleStyleSheet()["Title"]
    heading.fontSize = 40
    
    story=[]
    story.append(Paragraph(mealTime.name, heading))
    story.append(FrameBreak())
    story.append(NextPageTemplate("twoCol"))
    
    for first, last, table in data:
        story.append(Paragraph("%s %s: %s" % (first, last, table), normal))
    
    out = BytesIO()
    doc = BaseDocTemplate(out, pagesize=letter, author="Rectory School Seating Chart Generator", title=mealTime.name)
    
    top = Frame(doc.leftMargin, doc.height, doc.width, 100)
    frame1 = Frame(doc.leftMargin, doc.bottomMargin, doc.width/2-6, doc.height-75, id='col1')
    frame2 = Frame(doc.leftMargin+doc.width/2+6, doc.bottomMargin, doc.width/2-6, doc.height-75, id='col2')
    doc.addPageTemplates([PageTemplate(id='topColHeader',frames=[top, frame1,frame2]), ])
    
    frame1 = Frame(doc.leftMargin, doc.bottomMargin, doc.width/2-6, doc.height, id='col1')
    frame2 = Frame(doc.leftMargin+doc.width/2+6, doc.bottomMargin, doc.width/2-6, doc.height, id='col2')
    doc.addPageTemplates([PageTemplate(id='twoCol',frames=[frame1,frame2]), ])
    
    #start the construction of the pdf
    doc.build(story)
    
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = 'filename="{mealTime:} by student.pdf"'.format(mealTime=mealTime.name)

    response.write(out.getvalue())

    return response
开发者ID:rectory-school,项目名称:rectory-apps,代码行数:55,代码来源:display.py

示例8: pdfDocTemplate

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
def pdfDocTemplate(filename):
    """create document template sized as required"""

    doc = BaseDocTemplate(filename, pagesize = pdfPageSz, 
        leftMargin = pdfMargin, rightMargin = pdfMargin, topMargin = pdfMargin, 
        bottomMargin = pdfMargin, creator = gv.getVar('progName'),
        author = pdfAuthorTxt, subject = pdfSubjectTxt, title = pdfTitleTxt, 
        keywords = pdfKeywordsTxt, pageCompression = 1)
    # normal frame as for SimpleFlowDocument
    frameN = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height, id='normal')
    doc.addPageTemplates([PageTemplate(id = 'all',frames = frameN, onPage = allPages)])
    return doc
开发者ID:ciscrh,项目名称:python-crhLib,代码行数:14,代码来源:crhPDF.py

示例9: create_pdfdoc

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
def create_pdfdoc(dest_filename, story):
    pdf_doc = BaseDocTemplate(dest_filename, pagesize=PAGE_SIZE,
        leftMargin=SIDE_MARGIN_SIZE, rightMargin=SIDE_MARGIN_SIZE,
        topMargin=VERT_MARGIN_SIZE, bottomMargin=VERT_MARGIN_SIZE)
    main_frame = Frame(SIDE_MARGIN_SIZE, VERT_MARGIN_SIZE,
        PAGE_SIZE[0] - 2 * SIDE_MARGIN_SIZE, PAGE_SIZE[1] - 2 * VERT_MARGIN_SIZE,
        leftPadding = 0, rightPadding = 0, bottomPadding = 0,
        topPadding = 0, id = 'main_frame')
    main_template = PageTemplate(id = 'main_template', frames = [main_frame])
    pdf_doc.addPageTemplates([main_template])

    pdf_doc.build(story)
开发者ID:DustinEvans-Omnibond,项目名称:BayTrackerDataGenerator,代码行数:14,代码来源:pdf_generator.py

示例10: create_pdfdoc

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
def create_pdfdoc(pdfdoc, story):  
        """ 
        Creates PDF doc from story. 
        """  
        pdf_doc = BaseDocTemplate(pdfdoc, pagesize = PAGE_SIZE,  
            leftMargin = MARGIN_SIZE, rightMargin = MARGIN_SIZE,  
            topMargin = MARGIN_SIZE, bottomMargin = MARGIN_SIZE)  
        main_frame = Frame(MARGIN_SIZE, MARGIN_SIZE,  
            PAGE_SIZE[0] - 2 * MARGIN_SIZE, PAGE_SIZE[1] - 2 * MARGIN_SIZE,  
            leftPadding = 0, rightPadding = 0, bottomPadding = 0,  
            topPadding = 0, id = 'main_frame')  
        main_template = PageTemplate(id = 'main_template', frames = [main_frame])  
        pdf_doc.addPageTemplates([main_template])  
      
        pdf_doc.build(story)  
开发者ID:liyang19901122,项目名称:GMS,代码行数:17,代码来源:print2.py

示例11: create_pdfdoc

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
 def create_pdfdoc(pdfdoc, story, with_watermark):
     def generate_watermark(canvas, doc):
         if not with_watermark: return
         canvas.saveState()
         canvas.setFont("Courier", 60)
         canvas.translate(700, 50)
         canvas.setFillGray(0.8, 0.5)
         canvas.rotate(45)
         for z in range(0, 1200, 60):
             canvas.drawCentredString(0, z, with_watermark)
         canvas.restoreState()
     pdf_doc = BaseDocTemplate(pdfdoc, pagesize=PAGE_SIZE, leftMargin=MARGIN_SIZE, topMargin=MARGIN_SIZE, rightMargin=MARGIN_SIZE, bottomMargin=MARGIN_SIZE)
     main_frame = Frame(MARGIN_SIZE, MARGIN_SIZE, PAGE_SIZE[0] - 2 * MARGIN_SIZE, PAGE_SIZE[1] - 2 * MARGIN_SIZE, leftPadding=0, rightPadding=0, topPadding=0, bottomPadding=0, id='mainframe')
     main_template = PageTemplate(id='maintemplate', frames=[main_frame], onPage=generate_watermark)
     pdf_doc.addPageTemplates([main_template])
     pdf_doc.build(story)
开发者ID:icucinema,项目名称:cintranet,代码行数:18,代码来源:bor_generator.py

示例12: listin_telefonico

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
def listin_telefonico(request, curso=None, grupo=None):
    if not curso:
        curso = request.session.get('curso_academico').get('pk')
    else:
        curso_qs = Curso.objects.filter(slug=curso)
        if curso_qs:
            curso = curso_qs[0].id
        else:
            raise Http404
    alumnos = CursoGrupoAlumno.objects.filter(curso_grupo__curso_id=curso).order_by('curso_alumno__alumno')
    if grupo:
        alumnos = alumnos.filter(curso_grupo__grupo__grupo=grupo).order_by('curso_alumno__alumno')
    if len(alumnos) == 0:
        raise Http404
    # Create the HttpResponse object with the appropriate PDF headers.
    response = HttpResponse(content_type='application/pdf')
    # response['Content-Disposition'] = 'attachment; filename="listin.pdf"'
    response['Content-Disposition'] = 'filename="listin.pdf"'
    # Create the PDF object, using the response object as its "file."
    buff = BytesIO()
    styles = getSampleStyleSheet()
    Elements = []
    doc = BaseDocTemplate(buff, leftMargin=2 * cm, rightMargin=0.5 * cm,
                          topMargin=2 * cm, bottomMargin=1 * cm, showBoundary=0)
    cabecera1 = request.session.get('centro', Configies.objects.all()[0].nombre_centro)
    cabecera2 = "Curso " + str(alumnos[0].curso_grupo.curso) + " - Listado telefónico de alumno/as " + (
    ("- Grupo: " + grupo) if grupo else "")

    def cabeceraYpie(canvas, doc):
        canvas.saveState()
        canvas.setFont('Helvetica-Bold', 14)
        canvas.drawCentredString(21 * cm / 2, 29 * cm, cabecera1)
        canvas.drawCentredString(21 * cm / 2, 28 * cm, cabecera2)
        canvas.setFont('Times-Roman', 10)
        canvas.drawCentredString(21 * cm / 2, cm, "Página {}".format(doc.page))
        canvas.restoreState()

    # normal frame as for SimpleFlowDocument
    frameT = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height, id='normal')
    for alumno in alumnos:
        Elements.append(EntradaListin(alumno=alumno))
    doc.addPageTemplates([PageTemplate(id='OneCol', frames=frameT, onPage=cabeceraYpie)])
    # start the construction of the pdf
    doc.build(Elements)
    response.write(buff.getvalue())
    buff.close()
    return response
开发者ID:pkom,项目名称:gesties,代码行数:49,代码来源:listados.py

示例13: __init__

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
class Sheet:
    """
    Base class for sheets of labels.
    """
    def __init__(self, buffer=None, debug=False):
        # Buffer must be set!
        if buffer is None:
            raise ValueError('Buffer argument is required')
        else:
            self.buffer = buffer
        self.debug = debug

        # Label parameters are for Avery 6572.
        # TODO: allow this to be set via options or some other way.
        # ... a horrible part of me is considering adding a model for label sheets.
        self.width = 612
        self.height = 792
        self.top_margin = 36
        self.bottom_margin = 36
        self.left_margin = 9
        self.right_margin = 9
        self.rows = 5
        self.cols = 3
        self.row_gutter = 0
        self.col_gutter = 9

        # Calculate label width and height.
        self.labelw = int((self.width - self.left_margin - self.right_margin - (self.cols - 1) * self.col_gutter) / self.cols)
        self.labelh = int((self.height - self.top_margin - self.bottom_margin - (self.rows - 1) * self.row_gutter) / self.rows)

        # Get sample style sheet from styles.
        self.styles = getSampleStyleSheet()
        self.style = self.styles['Normal']

        # Create document from base template.
        self.doc = BaseDocTemplate(self.buffer, pagesize=(self.width, self.height))

        # Construct page template of "frames".  Each frame contains one label.
        self.framelist = [(self.left_margin + y * (self.col_gutter + self.labelw), self.height - self.bottom_margin - self.labelh - x * (self.row_gutter + self.labelh), self.labelw, self.labelh) for x in range(self.rows) for y in range(self.cols)]
        self.doc.addPageTemplates([PageTemplate(frames=[Frame(a, b, c, d, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0, showBoundary=(1 if self.debug else 0)) for (a, b, c, d) in self.framelist])])

    def __call__(self, data):
        # table style for outer table is middle center
        ts = [('ALIGN', (0, 0), (0, 0), 'CENTER'), ('VALIGN', (0, 0), (0, 0), 'MIDDLE')]
        # labels are list of tables containing actual rendered records
        Sheet = [Table([[record.render(self)]], style=ts, colWidths=self.labelw, rowHeights=self.labelh) for record in data]
        self.doc.build(Sheet)
开发者ID:mathuin,项目名称:pyment,代码行数:49,代码来源:labels.py

示例14: create

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
    def create(self):
        from reportlab.platypus import BaseDocTemplate, PageTemplate
        from reportlab.lib.units import mm

        with tempfile.NamedTemporaryFile(suffix=".pdf") as f:
            Report.register_fonts()
            doc = BaseDocTemplate(f.name, pagesize=self.pagesize,
                                  leftMargin=15 * mm,
                                  rightMargin=15 * mm,
                                  topMargin=20 * mm,
                                  bottomMargin=15 * mm)
            doc.addPageTemplates([
                PageTemplate(id='All', frames=self.get_frames(doc), onPage=self.on_page, pagesize=self.pagesize)
            ])
            doc.build(self.get_story(doc))
            f.seek(0)
            return f.read()
开发者ID:JRodDynamite,项目名称:pretix,代码行数:19,代码来源:exporters.py

示例15: _create_pdfdoc

# 需要导入模块: from reportlab.platypus import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.BaseDocTemplate import addPageTemplates [as 别名]
def _create_pdfdoc(pdfdoc, story):
    """
    Creates PDF doc from story.
    """
    pdf_doc = BaseDocTemplate(
        pdfdoc, pagesize=letter,
        leftMargin=inch, rightMargin=inch,
        topMargin=inch, bottomMargin=inch)
    main_frame = Frame(
        inch, inch,
        letter[0] - 2 * inch, letter[1] - 2 * inch,
        leftPadding=0, rightPadding=0, bottomPadding=0,
        topPadding=0, id='main_frame')
    main_template = PageTemplate(id='main_template', frames=[main_frame])
    pdf_doc.addPageTemplates([main_template])

    pdf_doc.build(story)
开发者ID:jeffbaumes,项目名称:schoolplanner,代码行数:19,代码来源:__init__.py


注:本文中的reportlab.platypus.BaseDocTemplate.addPageTemplates方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。