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


Python Canvas.rotate方法代码示例

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


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

示例1: __init__

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import rotate [as 别名]
class AwardPrinter:
  def __init__(self, output_filename, background_image, page_renderer):
    self.background_image = background_image
    self.page_renderer = page_renderer
    self.pdf = Canvas(output_filename, pagesize = A4)        
  
  def draw(self, students):
    for student in students:
        self._draw_page(student)
    self.pdf.save()    
  
  def _draw_page(self, student):
    self.pdf.setFillColor(colors.black)
    # export the image as a higter resolution image 1280x920 recommended, which is then reduced 
    # in size to have a higher resolution for printing
    self.pdf.drawImage(self.background_image, .1 * inch, .3 * inch, width=580, height=800, preserveAspectRatio=True)
    self.pdf.rotate(270)
    self.page_renderer(self, student)
    self.pdf.showPage()    
      
  def _draw_award(self, student):
    name = student.split(',')[0].strip()
    award = student.split(',')[1].strip()
    self.pdf.setFont("Helvetica", 28)
    # play with these dimensions if you want to move around the text in the screen
    self.pdf.drawCentredString(-5.4 * inch, 4.5 * inch, name.encode('latin-1'))
    self.pdf.setFont("Helvetica", 18)
    # play with these dimensions if you want to move around the text in the screen
    self.pdf.drawCentredString(-5.4 * inch, 3.5 * inch, award)
    
  def _draw_certificate(self, student):
    name = student.split(',')[0].strip()    
    self.pdf.setFont("Helvetica", 32)
    # play with these dimensions if you want to move around the text in the screen
    self.pdf.drawCentredString(-5.75 * inch, 5.5 * inch, name.encode('latin-1'))
开发者ID:jawspeak,项目名称:twu-pdf-award-printers,代码行数:37,代码来源:award_generator.py

示例2: _get_output_page

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import rotate [as 别名]
    def _get_output_page(self, output_infos):
        inch = 72
        buf = io.BytesIO()
        canvas = Canvas(buf, pagesize=(8.5*inch, 11*inch))

        for info in output_infos:
            canvas.saveState()
            x, y = info.translate
            # We flip the y coordinate since that's how PDF programs give us
            # the number of pixels from the top, not the bottom.
            y = 11*inch - y
            canvas.translate(x, y)
            if info.rotate != 0:
                canvas.rotate(info.rotate)

            t = canvas.beginText()
            t.setFont('Courier', 10)
            t.setTextOrigin(0, 0)
            t.textLines(info.text)
            canvas.drawText(t)

            canvas.restoreState()

        canvas.save()
        return PdfFileReader(buf).getPage(0)
开发者ID:feihong,项目名称:ebay-tools,代码行数:27,代码来源:packinginfo.py

示例3: badge

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import rotate [as 别名]
def badge():
    name = request.form['name'][:MAX_CHARS_PER_LINE] if 'name' in request.form else ''
    name2 = request.form['name2'][:MAX_CHARS_PER_LINE] if 'name2' in request.form else ''
    nick = request.form['nick'][:MAX_CHARS_PER_LINE] if 'nick' in request.form else ''
    community = request.form['community'][:MAX_CHARS_PER_LINE] if 'community' in request.form else ''

    pdf = BytesIO()
    c = Canvas(pdf, pagesize=(BADGE_W, BADGE_H))

    c.translate(ORIGIN_X, ORIGIN_Y)

    ico_center = 7*mm
    offset = HEIGHT+2*mm

    c.setFillGray(0.66)
    c.setFont('Awesome', 42)
    c.drawCentredString(ico_center, offset-42*pica/12, '\uf007')
    c.setFont('Awesome', 38)
    c.drawCentredString(ico_center, offset-(2*42+40)*pica/12, '\uf1fa')
    c.drawCentredString(ico_center, offset-(2*42+2*40)*pica/12, '\uf041')

    txt_start = 15*mm

    c.setFillGray(0.0)
    c.setFont('LeagueGothic', 42)
    c.drawString(txt_start, offset-42*pica/12, name)
    c.drawString(txt_start, offset-2*42*pica/12, name2)
    c.setFont('LeagueGothic', 38)
    c.drawString(txt_start, offset-(2*42+40)*pica/12, nick)
    c.drawString(txt_start, offset-(2*42+2*40)*pica/12, community)

    evt_width = 38*pica/12
    evt_start = WIDTH - evt_width

    img_width = 20*mm
    img_start = evt_start - img_width
    c.drawImage(path.join(path.dirname(__file__), 'images/ffrhein_logo_claim_line_rot.png'), img_start, 0, img_width, HEIGHT, mask=None, preserveAspectRatio=True, anchor='c')

    c.rotate(90)
    c.rect(0, -WIDTH, HEIGHT, evt_width, 0, 1)
    c.setFillGray(1.0)
    c.drawCentredString(HEIGHT/2, -WIDTH+MARGIN_R, 'routing days')  

    c.showPage()
    c.save()
    _print(pdf.getvalue())
    pdf.close()

    # response = make_response('Meh')
    # response.headers['Content-Type'] = 'text/plain'
    # return response
    return redirect('/badge/printing.html')
开发者ID:docloy,项目名称:badge-o-matic,代码行数:54,代码来源:webapp.py

示例4: test_03_draw

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import rotate [as 别名]
 def test_03_draw(self):
     from reportlab.lib.pagesizes import A4
     from reportlab.pdfgen.canvas import Canvas
     from reportlab.lib.units import inch
     c = Canvas('demo.pdf', pagesize=A4)
     c.translate(inch,inch)
     c.setFont("Helvetica", 14)
     c.setStrokeColorRGB(0.2,0.5,0.3)
     c.setFillColorRGB(1,0,1)
     c.line(0,0,0,1.7*inch)
     c.line(0,0,1*inch,0)
     c.rect(0.2*inch, 0.2*inch, 1*inch, 1.5*inch,fill=1)
     c.rotate(90)
     c.setFillColorRGB(0,0,0.77)
     c.drawString(0.3*inch, -inch, "Hello World")
     c.showPage()
     c.save()
开发者ID:zenist,项目名称:ZLib,代码行数:19,代码来源:test_pdf.py

示例5: bl

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import rotate [as 别名]
        if verbose:
            print "%s: bl (%d,%d), tr (%d,%d), size (%d,%d), dpi (%g,%g)" % (
                image["filename"],
                image["x"], image["y"],
                image["x"]+image["w"], image["y"]+image["h"],
                image["w"], image["h"],
                image["pw"] * 72.0 / image["w"],
                image["ph"] * 72.0 / image["h"],
            )

        # Rotate.
        rotates = [
            lambda x,y,w,h: (x,y,w,h), # no rotation
            lambda x,y,w,h: (y, -x-w, h, w), # anticlockwise
            lambda x,y,w,h: (-x-w, -y-h, w, h), # 180
            lambda x,y,w,h: (-y-h, x, h, w), # clockwise
        ]
        image["x"], image["y"], image["w"], image["h"] = (
            rotates[angle](image["x"], image["y"], image["w"], image["h"])
        )

        # And draw the image.
        pdf.saveState()
        pdf.rotate(angle * 90)
        pdf.drawImage(img, image["x"], image["y"], image["w"], image["h"])
        pdf.restoreState()

    pdf.showPage()
pdf.save()
开发者ID:rdebath,项目名称:sgt,代码行数:31,代码来源:imagepdf.py

示例6: get

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import rotate [as 别名]
    def get(self, request, *args, **kwargs):
        self.object = self.get_object()

        response = HttpResponse(content_type='application/pdf')
        response['Content-Disposition'] = 'attachment; filename="{0}-{1}.pdf"'.format(self.object.registru.serie, self.object.numar_inregistrare)

        pdf = Canvas(response, pagesize = A4)

        import os
        from reportlab.lib.styles import getSampleStyleSheet
        from reportlab.platypus import Paragraph

        pdfmetrics.registerFont(TTFont("DejaVuSans-Bold", "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf"))
        pdfmetrics.registerFont(TTFont("DejaVuSans", "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"))

        if self.object.registru.centru_local.antet:
            antet_path = os.path.join(settings.MEDIA_ROOT, "%s" % self.object.registru.centru_local.antet)
            pdf.drawInlineImage(antet_path, 2.5 * cm, 10.8 * cm, width=16. * cm, height=2.66 * cm)
            pdf.drawInlineImage(antet_path, 2.5 * cm, 24.5 * cm, width=16. * cm, height=2.66 * cm)
        pdf.setStrokeColorRGB(0, 0, 0)
        pdf.rect(2. * cm, 2. * cm, 17. * cm, 12. * cm)
        pdf.rect(2. * cm, 15.7 * cm, 17. * cm, 12 * cm)

        pdf.setStrokeColorRGB(0.5, 0.5, 0.5)
        pdf.setDash(1, 2)
        pdf.line(0 * cm, 14.85 * cm, 21. * cm, 14.85 * cm)

        pdf.setFont("DejaVuSans-Bold", 0.5 * cm, leading=None)
        pdf.drawCentredString(10.5 * cm, 9.5 * cm, u"Chitanță")
        pdf.drawCentredString(10.5 * cm, 23.2 * cm, u"Chitanță")

        text_serie = u"seria {0}, nr. {1} / {2}".format(self.object.registru.serie, self.object.numar_inregistrare,
                                                       self.object.data_inregistrare.strftime("%d.%m.%Y"))

        pdf.setFont("DejaVuSans-Bold", 4. * cm, leading=None)
        pdf.setFillColorRGB(0.95, 0.95, 0.95)
        pdf.rotate(15)
        pdf.drawString(4.5 * cm, 2. * cm, u"COPIE")
        pdf.rotate(-15)

        pdf.setFillColorRGB(0, 0, 0)
        pdf.setFont("DejaVuSans", 0.35 * cm, leading=None)
        pdf.drawCentredString(10.5 * cm, 8.9 * cm, text_serie)
        pdf.drawCentredString(10.5 * cm, 22.6 * cm, text_serie)

        reprezinta = self.object.descriere
        if hasattr(self.object, "chitantacotizatie"):
            reprezinta = []
            for p in self.object.chitantacotizatie.platacotizatietrimestru_set.all().order_by("index"):
                date_reprezinta = (p.trimestru.__unicode__(), p.suma, u"- parțial" if p.partial else "")
                reprezinta.append("{0} ({1} RON{2})".format(*date_reprezinta))
            reprezinta = ", ".join(reprezinta)
            reprezinta = u"cotizație membru pentru {0}".format(reprezinta)
        date_chitanta = (self.object.platitor().__unicode__(), self.object.suma, suma2text(self.object.suma).strip(), reprezinta)
        text_chitanta = u"Am primit de la <strong>{0}</strong> suma de {1} lei, adică {2}, reprezentând {3}.".format(*date_chitanta)

        style_sheet = getSampleStyleSheet()
        style = style_sheet['Normal']
        style.alignment = TA_JUSTIFY
        style.fontName = "DejaVuSans"
        style.leading = 0.85 * cm

        paragraph = Paragraph(text_chitanta, style)
        w, h  = paragraph.wrap(15. * cm, 5. * cm)
        # print w, h

        paragraph.drawOn(pdf, 3. * cm, 5.5 * cm)
        paragraph.drawOn(pdf, 3. * cm, 19.2 * cm)

        pdf.drawString(12.5 * cm, 4.5 * cm, u"Casier,")
        pdf.drawString(12.5 * cm, 18.2 * cm, u"Casier, ")

        trezorier = self.object.registru.centru_local.ocupant_functie(u"Trezorier Centru Local")
        pdf.drawString(12.5 * cm, 3.8 * cm, trezorier.__unicode__())
        pdf.drawString(12.5 * cm, 17.5 * cm, trezorier.__unicode__())


        pdf.showPage()
        pdf.save()

        return response
开发者ID:andreiavram,项目名称:scoutfile,代码行数:83,代码来源:views.py

示例7: render

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import rotate [as 别名]
    def render(self, outfile, font_name, font_size):
        """
        Render the binary heat map as a PDF to the file-like object or filename
        ``outfile``.  All text will be typeset in the font named ``font_name``
        at size ``font_size``.
        """
        c = Canvas(outfile)
        c.setFont(font_name, font_size)
        leftlen = max(map(c.stringWidth, self.row_labels)) + LABEL_PAD * 2
        toplen  = max(map(c.stringWidth, self.column_labels)) + LABEL_PAD * 2
        miny = self.rows * font_size * 1.2
        maxx = self.columns * font_size * 1.2
        c.setPageSize((leftlen + maxx + PADDING*2, miny + toplen + PADDING*2))
        # Set coordinates so that LL corner has coord (-leftlen-PADDING,
        # -miny-PADDING) and the origin is at the point where the borders of the
        # row & column labels meet:
        c.translate(leftlen+PADDING, miny+PADDING)

        lineheight = font_size * 1.2
        radius = lineheight / 3

        c.setFillColorRGB(*COL_BG_COLOR)
        for i in range(0, self.columns, 2):
            c.rect(
                i * lineheight,
                -miny,
                lineheight,
                miny + toplen,
                stroke=0,
                fill=1,
            )

        c.setFillColorRGB(*ROW_BG_COLOR)
        for i in range(2, self.rows+1, 2):
            # Yes, it starts at 2, so that the positive rectangle height will
            # make it fill row 1.
            c.rect(
                -leftlen,
                -i * lineheight,
                leftlen + maxx,
                lineheight,
                stroke=0,
                fill=1,
            )

        c.setFillColorRGB(0, 0, 0)
        c.line(0, toplen, 0, -miny)
        c.line(-leftlen, 0, maxx, 0)

        for i, label in enumerate(self.row_labels):
            c.drawRightString(
                -LABEL_PAD,
                -(i+1) * lineheight + font_size / 3,
                label,
            )

        for i, label in enumerate(self.column_labels):
            c.saveState()
            c.translate((i+1) * lineheight, 0)
            c.rotate(90)
            c.drawString(LABEL_PAD, font_size / 3, label)
            c.restoreState()

        for row, col in self.get_indexed_pairs():
            c.circle(
                (col+0.5) * lineheight,
                -(row+0.5) * lineheight,
                radius,
                stroke=0,
                fill=1,
            )

        c.showPage()
        c.save()
开发者ID:jwodder,项目名称:binheat,代码行数:76,代码来源:binheat.py

示例8: PDFInvoice

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import rotate [as 别名]
class PDFInvoice(object):
	def __init__(self, recipient, invoicedate, duedate, invoicenum=None, imagedir=None, currency='€', preview=False, receipt=False, bankinfo=True):
		self.pdfdata = StringIO.StringIO()
		self.canvas = Canvas(self.pdfdata)
		self.recipient = recipient
		self.invoicenum = invoicenum
		self.invoicedate = invoicedate
		self.duedate = duedate
		self.imagedir = imagedir or '.'
		self.currency = currency or '€'
		self.preview = preview
		self.receipt = receipt
		self.bankinfo = bankinfo
		self.rows = []

		if self.receipt:
			# Never include bank info on receipts
			self.bankinfo = False

		self.canvas.setTitle("PostgreSQL Europe Invoice #%s" % self.invoicenum)
		self.canvas.setSubject("PostgreSQL Europe Invoice #%s" % self.invoicenum)
		self.canvas.setAuthor("PostgreSQL Europe")
		self.canvas._doc.info.producer = "PostgreSQL Europe Invoicing System"

	def addrow(self, title, cost, count=1):
		self.rows.append((title, cost, count,))


	def trimstring(self, s, maxlen, fontname, fontsize):
		while len(s) > 5:
			if self.canvas.stringWidth(s, fontname, fontsize) <= maxlen:
				return s
			s = s[:len(s)-2]
		return s

	def _pageheader(self):
		if self.preview:
			t = self.canvas.beginText()
			t.setTextOrigin(6*cm, 4*cm)
			t.setFont("Times-Italic", 70)
			t.setFillColorRGB(0.9,0.9,0.9)
			t.textLines("PREVIEW PREVIEW")
			self.canvas.rotate(45)
			self.canvas.drawText(t)
			self.canvas.rotate(-45)

		im = Image("%s/PostgreSQL_logo.1color_blue.300x300.png" % self.imagedir, width=3*cm, height=3*cm)
		im.drawOn(self.canvas, 2*cm, 25*cm)
		t = self.canvas.beginText()
		t.setFillColorRGB(0,0,0,0)
		t.setFont("Times-Roman", 10)
		t.setTextOrigin(6*cm, 27.5*cm)
		t.textLines("""PostgreSQL Europe
Carpeaux Diem
13, rue du Square Carpeaux
75018 PARIS
France
""")
		self.canvas.drawText(t)

		t = self.canvas.beginText()
		t.setTextOrigin(2*cm, 23*cm)
		t.setFont("Times-Roman", 10)
		t.textLine("")
		t.textLines("""
Your contact: Guillaume Lelarge
Function: PostgreSQL Europe Treasurer
E-mail: [email protected]
""")
		self.canvas.drawText(t)

		t = self.canvas.beginText()
		t.setTextOrigin(11*cm, 23*cm)
		t.setFont("Times-Italic", 11)
		t.textLine("To:")
		t.setFont("Times-Roman", 11)
		t.textLines(self.recipient)
		self.canvas.drawText(t)

		p = self.canvas.beginPath()
		p.moveTo(2*cm, 18.9*cm)
		p.lineTo(19*cm, 18.9*cm)
		self.canvas.drawPath(p)


	def save(self):
		# We can fit 15 rows on one page. We might want to do something
		# cute to avoid a single row on it's own page in the future, but
		# for now, just split it evenly.
		for pagenum in range(0, (len(self.rows)-1)/15+1):
			self._pageheader()
			islastpage = (pagenum == (len(self.rows)-1)/15)

			if len(self.rows) > 15:
				suffix = " (page %s/%s)" % (pagenum+1, len(self.rows)/15+1)
			else:
				suffix = ''

			# Center between 2 and 19 is 10.5
			if self.invoicenum:
#.........这里部分代码省略.........
开发者ID:louiseGrandjonc,项目名称:pgeu-website,代码行数:103,代码来源:pgeuinvoice.py

示例9: __call__

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import rotate [as 别名]
 def __call__(self, data):
     """
     Generate the PDF
     """
     icon = self.settings['icons'].get(data['issue_type'], self.settings['icons']['Unknown'])
     priority_icon = self.settings['priority_icons'].get(data['priority'], self.settings['priority_icons']['Unknown'])
     priority_color = self.settings['priority_colors'].get(data['priority'], self.settings['priority_colors']['Unknown'])
     
     styles = self._getStyleSheet()
     
     canvas = Canvas(self.output, pagesize=self.settings['pagesize'])
     
     margin = self.settings['margin']
     page_width, page_height = self.settings['pagesize']
     
     frame_width = page_width-(margin*2)
     frame_height = page_height-(margin*2)
     
     main = Frame(margin, margin, frame_width, frame_height, showBoundary=0, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0)
     footer = Frame(margin, margin, frame_width, frame_height, showBoundary=0, leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0)
     
     if data['border']:
         canvas.setLineWidth(0.5)
         canvas.rect(1, 1, page_width-2, page_height-2, stroke=1, fill=0)
         
     # label the checkbox arrays with a rotated text label
     canvas.saveState()
     canvas.setFillColor((0.9, 0.9, 0.9))
     canvas.setFont('Helvetica-Bold', 20)
     canvas.translate(margin*2, margin*2)
     canvas.rotate(15)
     canvas.drawString(0, -10, "INTERRUPTED")
     canvas.restoreState()
     
     canvas.saveState()
     canvas.setFillColor((0.9, 0.9, 0.9))
     canvas.setFont('Helvetica-Bold', 20)
     canvas.translate(frame_width/2+(inch*0.6), margin*2)
     canvas.rotate(15)
     canvas.drawString(0, -10, "BLOCKED")
     canvas.restoreState()
     
     ######### use a table to hold the header
     #
     # +--------+-------------------------+-------+
     # | ID     | Reporter                | Icon  |
     # | Type   | Created Date            |       |
     # +--------+-------------------------+-------+
     #
     # Illustrates the use of inline styling.
     #
     # @TODO: move the inline styles to the style sheet
     
     header_data = [
         [ 
           Image(icon, inch*0.4, inch*0.4),
           [
            Paragraph('<para size="18"><b>%(issue_id)s</b></para>' % data, styles['BodyText']), 
            Spacer(1,2),
            Paragraph('<para size="8">%(issue_type)s</para>' % data, styles['BodyText']),
           ],
           [
            Paragraph('<para size="16" alignment="center"><u>%(reporter)s</u></para>' % data, styles['BodyText']),  
            Spacer(1,2),
            Paragraph('<para size="10" alignment="center"><b>Opened: %s</b></para>' % data['date'].strftime('%m/%d @ %I:%M %p'), styles['BodyText']), 
           ],
           # XBox(inch*0.4, inch*0.4, ""),
           Image(priority_icon, inch*0.4, inch*0.4),
         ],
     ]
     
     # set the alignment
     header_style = TableStyle([
         ('ALIGNMENT',       (0,0),  (-1,-1),  'CENTER'), 
         ('VALIGN',          (0,0),  (-1,-1),  'MIDDLE'),
         ('LEFTPADDING',     (0,0),  (-1,-1),  3),
         ('RIGHTPADDING',    (0,0),  (-1,-1),  3),
         ('TOPPADDING',      (0,0),  (-1,-1),  3),
         ('BOTTOMPADDING',   (0,0),  (-1,-1),  3),
         ('BACKGROUND',      (0,0),  (-1,-1), priority_color),
         ('BOX',             (0,0),  (-1,-1), 0.5, black),
         # exceptions for the first cell
         ('ALIGNMENT',       (0,0),  (0,0),  'LEFT'), 
     ])
     
     header = Table(header_data, colWidths=[ 0.6*inch, inch*1.2, None, 0.6*inch], style=header_style)
     
     # The text of the story
     story = Paragraph("<b>"+data['summary']+"</b>", styles['BodyText'])
     
     # the text of the description - just the first 20 words 
     detail_words = data['detail'].split()
     
     short_detail = " ".join(detail_words[:50])
     
     if len(detail_words) > 50:
         short_detail += '...'
     
     details = KeepInFrame(frame_width, frame_height/3, [Paragraph(short_detail, styles['BodyText']),], mode="shrink", mergeSpace=0)
     
#.........这里部分代码省略.........
开发者ID:jjmojojjmojo,项目名称:jira-autoprint,代码行数:103,代码来源:issuecard.py

示例10:

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import rotate [as 别名]
pdf.drawString(centerh - x/2, 370, DATE)
pdf.setFont(FONT, FONTSIZE) # heure
x = pdf.stringWidth(TIME, FONT, FONTSIZE)
pdf.drawString(centerh - x/2, 325, TIME)
x = pdf.stringWidth(ADDRESS1, FONT, FONTSIZE) # adresse ligne 1
pdf.drawString(centerh - x/2, 280, ADDRESS1)
x = pdf.stringWidth(ADDRESS2, FONT, FONTSIZE) # adresse ligne 2
pdf.drawString(centerh - x/2, 245, ADDRESS2)
pdf.setFont(FONT, FONTSIZE2) # Renseignements et inscription
chaine = "Renseignements et inscription :"
x = pdf.stringWidth(chaine, FONT, FONTSIZE2)
pdf.drawString(centerh + 140 - x/2, 150, chaine)
pdf.setFont(FONTBOLD, FONTSIZE2) # site web LiLiT
chaine = "http://www.lilit.be/lip"
x = pdf.stringWidth(chaine, FONTBOLD, FONTSIZE2)
pdf.drawString(centerh + 140 - x/2, 100, chaine)
pdf.setFont(FONT, FONTSIZE2) # Gratuit et ouvert à tous !
chaine = "Gratuit et ouvert à tous !"
x = pdf.stringWidth(chaine, FONT, FONTSIZE2)
pdf.drawString(centerh + 140 - x/2, 50, chaine)
# Putting the copyright notice
pdf.setFont(FONT, SMALLFONTSIZE)
y = pdf.stringWidth(COPYRIGHT, "Times-Roman", SMALLFONTSIZE)
pdf.rotate(90)
pdf.drawString(5, -height + SMALLFONTSIZE, COPYRIGHT)

# close the page
pdf.showPage()
# save the PDF
pdf.save()
开发者ID:jepoirrier,项目名称:miscScripts,代码行数:32,代码来源:lipflyergenerator.py

示例11: remplissage

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import rotate [as 别名]
can.setFillColorCMYK(.7,0,.5,0)                 # couleur de remplissage (CMJN)
can.ellipse(3*cm, 4*cm, 19*cm, 10*cm, fill=1)   # ellipse (! axes = 16 x 6 cm)
can.setLineWidth(1)                             # nouvelle épaisseur des lignes
can.ellipse(centreX -.5*cm, centreY -.5*cm,     # petit cercle indiquant la
            centreX +.5*cm, centreY +.5*cm)     # position du centre de la page

# Quelques textes, avec polices, orientation et alignement divers :
can.setFillColor("navy")                        # couleur des textes
texteC ="Petite pluie abat grand vent."         # texte à centrer
can.setFont("Times-Bold", 18)
can.drawCentredString(centreX, centreY, texteC)
texteG ="Qui ne risque rien, n'a rien."         # texte à aligner à gauche
can.setFont("Helvetica", 18)
can.drawString(centreX, centreY -1*cm, texteG)
texteD ="La nuit porte conseil."                # texte à aligner à droite
can.setFont("Courier", 18)
can.drawRightString(centreX, centreY -2*cm, texteD)
texteV ="L'espoir fait  vivre."                 # texte à disposer verticalement
can.rotate(90)
can.setFont("Times-Italic", 18)
can.drawString(centreY +1*cm, -centreX, texteV) # ! inversion des coordonnées !
texteE ="L'exception confirme la règle"         # texte à afficher en blanc
can.rotate(-90)                                 # retour à l'orientation horiz.
can.setFont("Times-BoldItalic", 28)
can.setFillColor("white")                       # nouvelle couleur des textes
can.drawCentredString(centreX, 7*cm, texteE)

can.save()                                      # Sauvegarde du résultat

开发者ID:mseyne,项目名称:apprendre-python,代码行数:30,代码来源:imprimer_2.py

示例12: gen_bill_ride_stuff

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import rotate [as 别名]
def gen_bill_ride_stuff(ob):
    buffer_ = BytesIO()

    try:
        tree = ET.fromstring(ob.xml_content.encode('utf8'))
    except ET.ParseError:
        tree = None

    pagesize = A4
    margin = inch, inch, inch, inch

    canvas = Canvas(buffer_, pagesize=pagesize)

    c = RenderStack(0, 0, pagesize[0], pagesize[1], margin=margin)
    # p.roundRect(c.x(0), c.y(0), c.width(1), c.height(1), 3, stroke=1, fill=0)

    # Print warnings
    warnings = get_warning(ob)
    if warnings:
        canvas.saveState()
        grey = 0.3
        canvas.setFillColorCMYK(0, 0, 0, grey)
        canvas.setStrokeColorCMYK(0, 0, 0, grey)
        canvas.setFont("Helvetica", 50)

        total_height = 60 * len(warnings)
        canvas.translate(c.x(0.5), c.y(0.7))
        canvas.rotate(45)
        canvas.translate(0, total_height / 2)

        for item in warnings:
            canvas.drawCentredString(0, 0, item)
            canvas.translate(0, -60)

        canvas.restoreState()

    def add_items(items, showBoundary=False):
        f = Frame(c.x(0), c.y(0), c.width(1), c.height(1),
                  showBoundary=showBoundary,
                  leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0)
        f.addFromList(items, canvas)
        if items:
            raise Exception("Does not fit - items left")

    # Parameters
    column_height = 0.3
    column_width = 0.5
    footer_height = 0.14
    standard_separation = inch / 20

    # styles
    styles = getSampleStyleSheet()
    small = styles['Normal'].clone("Smaller", fontSize=8)
    normal = styles['Normal']
    bigheader = styles['h2']
    mediumheader = styles['h3']
    smallheader = styles['h4']

    with c.section(0, 1 - column_height, 1, 1):
        # columna izquierda
        with c.section(0, 0, column_width, 1,
                       margin=(0, 0, standard_separation, 0)):
            if ob.company.get_logo():
                with c.section(0, 0.5, 1, 1,
                               margin=standard_separation):
                    # logo
                    logo = ob.company.get_logo()
                    if logo:
                        add_items(
                            [get_image(logo.file.file.name, width=c.width(1), height=c.height(1))]
                        )
            with c.section(0, 0, 1, column_width,
                           margin=standard_separation):
                story = []
                if ob.company.nombre_comercial:
                    story.append(Paragraph(ob.company.nombre_comercial,
                                           bigheader))
                    story.append(Paragraph("Razon Social: {}".format(ob.company.razon_social),
                                           normal))
                else:
                    story.append(Paragraph("Razon Social: {}".format(ob.company.razon_social),
                                           bigheader))

                if ob.company.direccion_matriz != ob.punto_emision.establecimiento.direccion:
                    story.append(Paragraph(u"Dirección Matriz:",
                                           normal))
                    story.append(Paragraph(ob.company.direccion_matriz,
                                           small))
                    story.append(Paragraph(u"Dirección Sucursal:",
                                           normal))
                    story.append(Paragraph(ob.punto_emision.establecimiento.direccion,
                                           small))
                else:
                    story.append(Paragraph(u"Dirección:",
                                           normal))
                    story.append(Paragraph(ob.company.direccion_matriz,
                                           small))
                if ob.company.contribuyente_especial:
                    story.append(Paragraph("Contribuyente Especial: {}".format(ob.company.contribuyente_especial),
                                           normal))
#.........这里部分代码省略.........
开发者ID:javcasas,项目名称:tienda_ecuador,代码行数:103,代码来源:gen_ride.py


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