コード例 #1
0
ファイル: pagetemplates.py プロジェクト: ingob/mwlib.rl
    def beforeDrawPage(self,canvas,doc):
        canvas.setFont(serif_font,10)      
        canvas.setLineWidth(0)
        #header
        canvas.line(header_margin_hor, page_height - header_margin_vert, page_width - header_margin_hor, page_height - header_margin_vert )
        if pdfstyles.show_page_header:
            canvas.saveState()
            canvas.resetTransforms()
            canvas.translate(header_margin_hor, page_height - header_margin_vert - 0.1*cm)
            p = Paragraph(self.title, text_style())
            p.canv = canvas
            p.wrap(page_width - header_margin_hor*2.5, page_height) # add an extra 0.5 margin to have enough space for page number
            p.drawPara()
            canvas.restoreState()
            
        canvas.drawRightString(page_width - header_margin_hor, page_height - header_margin_vert + 0.1 * cm, "%d" % doc.page)

        #Footer
        canvas.saveState()
        canvas.setFont(serif_font,8)
        canvas.line(footer_margin_hor, footer_margin_vert, page_width - footer_margin_hor, footer_margin_vert )
        if pdfstyles.show_page_footer:
            p = Paragraph(formatter.cleanText(pagefooter, escape=False), text_style())
            p.canv = canvas
            w,h = p.wrap(page_width - header_margin_hor*2.5, page_height)
            p.drawOn(canvas, footer_margin_hor, footer_margin_vert - 10 - h)
        canvas.restoreState()
コード例 #2
0
ファイル: pagetemplates.py プロジェクト: tosher/mwlib.rl
 def beforeDrawPage(self, canvas, doc):
     canvas.setFont(serif_font, 8)
     canvas.saveState()
     if pdfstyles.show_title_page_footer:
         canvas.line(footer_margin_hor, footer_margin_vert, page_width - footer_margin_hor, footer_margin_vert)
         footertext = [_(titlepagefooter)]
         if pdfstyles.show_creation_date:
             locale.setlocale(locale.LC_ALL, "")
             footertext.append(
                 pdfstyles.creation_date_txt % time.strftime(pdfstyles.creation_date_format, time.localtime())
             )
         lines = [formatter.cleanText(line, escape=False) for line in footertext]
         txt = "<br/>".join(line if isinstance(line, unicode) else unicode(line, "utf-8") for line in lines)
         p = Paragraph(txt, text_style(mode="footer"))
         w, h = p.wrap(print_width, print_height)
         canvas.translate((page_width - w) / 2.0, footer_margin_vert - h - 0.25 * cm)
         p.canv = canvas
         p.draw()
     canvas.restoreState()
     if self.cover:
         width, height = self._scale_img(pdfstyles.title_page_image_size, self.cover)
         if pdfstyles.title_page_image_pos[0] is None:
             x = (page_width - width) / 2.0
         else:
             x = max(0, min(page_width - width, pdfstyles.title_page_image_pos[0]))
         if pdfstyles.title_page_image_pos[1] is None:
             y = (page_height - height) / 2.0
         else:
             y = max(0, min(page_height - height, pdfstyles.title_page_image_pos[1]))
         canvas.drawImage(self.cover, x, y, width, height)
コード例 #3
0
ファイル: pagetemplates.py プロジェクト: EtherGraf/mwlib.rl
 def beforeDrawPage(self,canvas,doc):
     canvas.setFont(serif_font,8)
     canvas.saveState()
     if pdfstyles.show_title_page_footer:
         canvas.line(footer_margin_hor, footer_margin_vert, page_width - footer_margin_hor, footer_margin_vert )
         footertext = [_(titlepagefooter)]
         if pdfstyles.show_creation_date:
             footertext.append('PDF generated at: %s' % strftime("%a, %d %b %Y %H:%M:%S %Z", gmtime()))
         p = Paragraph('<br/>'.join([formatter.cleanText(line, escape=False) for line in footertext]),
                       text_style(mode='footer'))
         w,h = p.wrap(print_width, print_height)
         canvas.translate( (page_width-w)/2.0, footer_margin_vert - h - 0.25*cm)
         p.canv = canvas
         p.draw()
     canvas.restoreState()
     if self.cover:
         width, height = self._scale_img(pdfstyles.title_page_image_size, self.cover)
         if pdfstyles.title_page_image_pos[0] == None:
             x = (page_width - width) / 2.0
         else:
             x = max(0, min(page_width-width, pdfstyles.title_page_image_pos[0]))
         if pdfstyles.title_page_image_pos[1] == None:
             y = (page_height - height) / 2.0
         else:
             y = max(0, min(page_height-height, pdfstyles.title_page_image_pos[1]))
         canvas.drawImage(self.cover, x, y, width , height)
コード例 #4
0
ファイル: pagetemplates.py プロジェクト: iwoj/mwlib.rl
    def beforeDrawPage(self, canvas, doc):
        canvas.setFont(serif_font, 10)
        canvas.setLineWidth(0)
        #header
        canvas.line(header_margin_hor, page_height - header_margin_vert,
                    page_width - header_margin_hor,
                    page_height - header_margin_vert)
        if pdfstyles.show_page_header:
            canvas.saveState()
            canvas.resetTransforms()
            if not self.rtl:
                h_offset = header_margin_hor
            else:
                h_offset = 1.5 * header_margin_hor
            canvas.translate(h_offset,
                             page_height - header_margin_vert - 0.1 * cm)
            p = Paragraph(self.title, text_style())
            p.canv = canvas
            p.wrap(
                page_width - header_margin_hor * 2.5, page_height
            )  # add an extra 0.5 margin to have enough space for page number
            p.drawPara()
            canvas.restoreState()

        if not self.rtl:
            h_pos = page_width - header_margin_hor
            d = canvas.drawRightString
        else:
            h_pos = header_margin_hor
            d = canvas.drawString
        #d(h_pos, page_height - header_margin_vert + 0.1 * cm, "%d" % doc.page)

        #Footer
        canvas.saveState()
        canvas.setFont(serif_font, 8)
        canvas.line(footer_margin_hor, footer_margin_vert,
                    page_width - footer_margin_hor, footer_margin_vert)
        if pdfstyles.show_page_footer:
            p = Paragraph(formatter.cleanText(pagefooter, escape=False),
                          text_style())
            p.canv = canvas
            w, h = p.wrap(page_width - header_margin_hor * 2.5, page_height)
            p.drawOn(canvas, footer_margin_hor, footer_margin_vert - 10 - h)
            d(page_width / 2, footer_margin_vert - 15 - h, "%d" % doc.page)
        canvas.restoreState()
コード例 #5
0
 def beforeDrawPage(self, canvas, doc):
     canvas.setFont(serif_font, 8)
     canvas.saveState()
     if pdfstyles.show_title_page_footer:
         canvas.line(footer_margin_hor, footer_margin_vert,
                     page_width - footer_margin_hor, footer_margin_vert)
         footertext = [_(titlepagefooter)]
         if pdfstyles.show_creation_date:
             locale.setlocale(locale.LC_ALL, '')
             footertext.append(pdfstyles.creation_date_txt % time.strftime(
                 pdfstyles.creation_date_format, time.localtime()))
         lines = [
             formatter.cleanText(line, escape=False) for line in footertext
         ]
         txt = '<br/>'.join(
             line if isinstance(line, unicode) else unicode(line, 'utf-8')
             for line in lines)
         p = Paragraph(txt, text_style(mode='footer'))
         w, h = p.wrap(print_width, print_height)
         canvas.translate((page_width - w) / 2.0,
                          footer_margin_vert - h - 0.25 * cm)
         p.canv = canvas
         p.draw()
     canvas.restoreState()
     if self.cover:
         width, height = self._scale_img(pdfstyles.title_page_image_size,
                                         self.cover)
         if pdfstyles.title_page_image_pos[0] == None:
             x = (page_width - width) / 2.0
         else:
             x = max(
                 0,
                 min(page_width - width, pdfstyles.title_page_image_pos[0]))
         if pdfstyles.title_page_image_pos[1] == None:
             y = (page_height - height) / 2.0
         else:
             y = max(
                 0,
                 min(page_height - height,
                     pdfstyles.title_page_image_pos[1]))
         canvas.drawImage(self.cover, x, y, width, height)
コード例 #6
0
ファイル: pagetemplates.py プロジェクト: iwoj/mwlib.rl
 def beforeDrawPage(self, canvas, doc):
     canvas.setFont(serif_font, 8)
     canvas.saveState()
     if pdfstyles.show_title_page_footer:
         canvas.line(footer_margin_hor, footer_margin_vert,
                     page_width - footer_margin_hor, footer_margin_vert)
         footertext = [_(titlepagefooter)]
         if pdfstyles.show_creation_date:
             footertext.append(
                 'PDF generated at: %s' %
                 strftime("%a, %d %b %Y %H:%M:%S %Z", gmtime()))
         p = Paragraph(
             '<br/>'.join([
                 formatter.cleanText(line, escape=False)
                 for line in footertext
             ]), text_style(mode='footer'))
         w, h = p.wrap(print_width, print_height)
         canvas.translate((page_width - w) / 2.0, 0.2 * cm)
         p.canv = canvas
         p.draw()
     canvas.restoreState()
     if self.cover:
         width, height = self._scale_img(pdfstyles.title_page_image_size,
                                         self.cover)
         if pdfstyles.title_page_image_pos[0] == None:
             x = (page_width - width) / 2.0
         else:
             x = max(
                 0,
                 min(page_width - width, pdfstyles.title_page_image_pos[0]))
         if pdfstyles.title_page_image_pos[1] == None:
             y = (page_height - height) / 2.0
         else:
             y = max(
                 0,
                 min(page_height - height,
                     pdfstyles.title_page_image_pos[1]))
         canvas.drawImage(self.cover, x, y, width, height)
コード例 #7
0
ファイル: pagetemplates.py プロジェクト: ingob/mwlib.rl
 def beforeDrawPage(self,canvas,doc):
     canvas.setFont(serif_font,8)
     canvas.saveState()
     if pdfstyles.show_title_page_footer:
         canvas.line(footer_margin_hor, footer_margin_vert, page_width - footer_margin_hor, footer_margin_vert )
         footertext = [_(titlepagefooter)]
         if pdfstyles.show_creation_date:
             footertext.append('PDF generated at: %s' % strftime("%a, %d %b %Y %H:%M:%S %Z", gmtime()))
         p = Paragraph('<br/>'.join([formatter.cleanText(line, escape=False) for line in footertext]),
                       text_style(mode='footer'))
         w,h = p.wrap(print_width, print_height)
         canvas.translate( (page_width-w)/2.0, 0.2*cm)
         p.canv = canvas
         p.draw()
     canvas.restoreState()
     if self.cover:
         width = 12 * cm
         img = Image.open(self.cover)
         w,h = img.size
         height = width/w*h 
         x = (page_width - width) / 2.0
         y = (page_height - height) / 2.0
         canvas.drawImage(self.cover, x, y, width , height)