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


Python Image.drawOn方法代码示例

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


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

示例1: _pageheader

# 需要导入模块: from reportlab.platypus.flowables import Image [as 别名]
# 或者: from reportlab.platypus.flowables.Image import drawOn [as 别名]
	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)
开发者ID:louiseGrandjonc,项目名称:pgeu-website,代码行数:50,代码来源:pgeuinvoice.py

示例2: __init__

# 需要导入模块: from reportlab.platypus.flowables import Image [as 别名]
# 或者: from reportlab.platypus.flowables.Image import drawOn [as 别名]
    def __init__(self, title, enterprise, interval, logo):
        self.title = title
        self.enterprise = enterprise
        self.interval = interval
        self.logo = logo
        self.width, self.height = A4
        self.buf = StringIO()
        self.canvas = Canvas(self.buf, pagesize=A4)

        self.page_title = ''
        self.page_rows = []
        self.page_frags = 0
        self.page_num = 1

        # Build story.
        self.canvas.saveState()
        self.canvas.setStrokeColor(colors.RED)
        self.canvas.setLineWidth(2)
        self.canvas.roundRect(self.margin, self.edenwall_height + self.margin, self.width, self.height, 20, stroke=1, fill=0)

        self.canvas.setFillColor(colors.GREEN2)
        self.canvas.setStrokeColor(colors.GREEN1)
        self.canvas.roundRect(- self.margin, - self.margin, self.width - self.margin, self.edenwall_height + self.margin,
                              20, stroke=1, fill=1)
        # TODO do not hardcode this values.
        img = Image('/var/lib/ufwi_rpcd/edenwall.png', 1209 / (300/(self.edenwall_height-self.margin/2)), self.edenwall_height-self.margin/2)
        img.drawOn(self.canvas, self.margin, self.margin/4)

        self.canvas.restoreState()

        if self.logo:
            img = Image(StringIO(self.logo))
            img._setup_inner()
            img.drawOn(self.canvas, (self.width - self.margin)/2 - img.drawWidth/2, 2*self.height/3)

        offset = 40

        self.canvas.setFillColor(black)
        self.canvas.setFont("Helvetica-Bold", self.big_title_height)
        self.canvas.drawCentredString((self.width-self.margin)/2, self.height/3, title)
        self.canvas.setFont("Helvetica-Bold", self.frag_title_height)
        self.canvas.drawString(offset, self.height - offset, enterprise)
开发者ID:maximerobin,项目名称:Ufwi,代码行数:44,代码来源:report.py

示例3: Dessine_texte

# 需要导入模块: from reportlab.platypus.flowables import Image [as 别名]
# 或者: from reportlab.platypus.flowables.Image import drawOn [as 别名]
    def Dessine_texte(self, texte="", nom_categorie=None, y=0, hauteur=0):
        """ Dessine le texte de la case """
        if texte == None :
            texte = ""

        # Dessine le nom de la catégorie
        if nom_categorie != None :
            self.canvas.saveState()
            self.canvas.setStrokeColor(ColorWxToPdf(self.parent.dictDonnees["case_titre_texte_couleur"], alpha=1))
            self.canvas.setFillColor(ColorWxToPdf(self.parent.dictDonnees["case_titre_texte_couleur"], alpha=1))
            self.canvas.setLineWidth(0.5)
            self.canvas.setDash(0.5, 4)
            self.canvas.line(0, self.hauteur_case - y +1, self.largeur_case, self.hauteur_case - y +1)

            self.canvas.setFont(self.parent.dictDonnees["case_titre_nom_police"], size=self.parent.dictDonnees["case_titre_taille_police"]-2)
            self.canvas.drawString(4, self.hauteur_case - y - 10, nom_categorie)
            self.canvas.restoreState()


        # Propriétés
        self.canvas.setFillColor(ColorWxToPdf(self.parent.dictDonnees["case_texte_couleur"], alpha=1))

        # Création des paragraphes
        taille_police = self.parent.dictDonnees["case_taille_police"]
        espace_vertical = self.parent.dictDonnees["case_espace_vertical"]
        liste_paragraphes, hauteur_paragraphes = self.GetParagraphes(texte, taille_police)
        ratio_depassement = (hauteur_paragraphes + (len(liste_paragraphes) - 1) * espace_vertical) / hauteur

        # Vérifie si le texte ne dépasse pas de la case
        if ratio_depassement > 1 :
            taille_police = taille_police / ratio_depassement
            liste_paragraphes, hauteur_paragraphes = self.GetParagraphes(texte, taille_police)

        # Calcule l'espace vertical et la marge supérieure
        if self.parent.dictDonnees["case_repartition_verticale"] == True :
            # marge_haut = self.parent.dictDonnees["case_marge_haut"]
            # espace_vertical = (hauteur - hauteur_paragraphes - marge_haut * 2) / (len(liste_paragraphes) - 1)
            bordure = 4
            espace_vertical = (hauteur - hauteur_paragraphes - bordure*2) / (len(liste_paragraphes) - 1 + 2)
            marge_haut = espace_vertical + bordure
        else :
            espace_vertical = self.parent.dictDonnees["case_espace_vertical"]
            marge_haut = (hauteur - (hauteur_paragraphes + (len(liste_paragraphes) - 1) * espace_vertical)) / 2.0

        # Préparation des images
        if self.parent.dictDonnees["case_separateur_type"] == "image" and self.parent.dictDonnees["case_separateur_image"] != "aucune":
            img = wx.Image(Chemins.GetStaticPath("Images/Menus/%s" % self.parent.dictDonnees["case_separateur_image"]), wx.BITMAP_TYPE_ANY)
            ratio_image = 1.0 * img.GetWidth() / img.GetHeight()
            largeur_image = self.largeur_case / 1.5
            hauteur_image = largeur_image / ratio_image
            separateur_image = Image(Chemins.GetStaticPath("Images/Menus/%s" % self.parent.dictDonnees["case_separateur_image"]), width=largeur_image, height=hauteur_image)

        # Dessine les lignes
        y_paragraphe = self.hauteur_case - y - marge_haut
        index = 0
        for hauteur_paragraphe, paragraphe in liste_paragraphes:
            y_paragraphe -= hauteur_paragraphe
            paragraphe.drawOn(self.canvas, 0, y_paragraphe)

            # Dessine l'image de séparation
            if self.parent.dictDonnees["case_separateur_type"] != "aucun" and index < len(liste_paragraphes) - 1:
                if self.parent.dictDonnees["case_separateur_type"] == "image" :
                    separateur_image.drawOn(self.canvas, self.largeur_case / 2.0 - separateur_image._width / 2.0, y_paragraphe - espace_vertical / 2.0 - separateur_image._height / 2.0)
                elif self.parent.dictDonnees["case_separateur_type"] == "ligne":
                    largeur_separateur = self.largeur_case / 3.5
                    x_separateur = (self.largeur_case - largeur_separateur) / 2.0
                    self.canvas.setStrokeColor(ColorWxToPdf(wx.WHITE, alpha=0.2))
                    self.canvas.setLineWidth(0.25)
                    self.canvas.line(x_separateur, y_paragraphe - espace_vertical / 2.0, x_separateur + largeur_separateur, y_paragraphe - espace_vertical / 2.0)

            y_paragraphe -= espace_vertical
            index += 1
开发者ID:bogucool,项目名称:Noethys,代码行数:74,代码来源:UTILS_Impression_menu.py

示例4: F116PdfOld

# 需要导入模块: from reportlab.platypus.flowables import Image [as 别名]
# 或者: from reportlab.platypus.flowables.Image import drawOn [as 别名]
class F116PdfOld(BasePdf):
    
    def __init__(self, data, debug=False):
        super(F116PdfOld, self).__init__(data, debug)
        if data:
            self.lside_data = data[0]
            self.rside_data = data[1]

    def create_pdf_file(self, file_name, page_size=landscape(A4)):
        super(F116PdfOld, self).create_pdf_file(file_name, page_size)
    
    def render_page1_image(self):
        A4_Width, A4_Height = A4
        self.im = Image(_self_path+ '/' + u'post1.JPG',width=A4_Height, height=A4_Width)
        self.im.drawOn(self.pdf, self.x(0), self.y(0))

    def render_page2_image(self):
        A4_Width, A4_Height = A4
        self.im = Image(_self_path+ '/' + u'post2.JPG',width=A4_Height, height=A4_Width)
        self.im.drawOn(self.pdf, self.x(0), self.y(0))


    def render_page1_oneside_data(self, side_data):
        self.pdf.setFont('DejaVuSans', 8)

        #money
        self.pdf.setFont('DejaVuSans', 12)
        self.pdf.drawString(self.x(2.05*cm), self.y(15.4*cm), side_data.sum + u" руб. 00 коп.")
        self.pdf.drawString(self.x(3.53*cm), self.y(4*cm), side_data.sum)
        
        #to
        self.pdf.setFont('DejaVuSans', 8)
        #name
        self.drawClippingString(side_data.to_name, self.x(3.12*cm), self.y(13.8*cm), 5.1*cm, 0.5*cm)
        #address - if need split
        if len(side_data.to_address) >= 33: # 33chars for font size 8
            #split to 2 line
            self.drawClippingString(side_data.to_address[:33], self.x(3.12*cm), self.y(13.35*cm), 5.1*cm, 0.5*cm)
            #if len(side_data.to_address[34:] >= ?)# need 3 line?
            self.drawClippingString(side_data.to_address[33:], self.x(2.02*cm), self.y(12.95*cm), 6.1*cm, 0.5*cm)
        else:
            self.drawClippingString(side_data.to_address, self.x(3.12*cm), self.y(13.35*cm), 5.1*cm, 0.5*cm)
            
        #zip_code
        zip_code = self.pdf.beginText()
        zip_code.setTextOrigin(self.x(5.39*cm), self.y(12.55*cm))
        zip_code.setFont('DejaVuSans', 10)
        zip_code.setCharSpace(8)
        zip_code.textLine(side_data.to_zip_code)
        zip_code.setCharSpace(0)
        self.pdf.drawText(zip_code)
        
        #from
        #name
        self.drawClippingString(side_data.from_name, self.x(3.5*cm), self.y(12*cm), 9.05*cm, 0.5*cm)
        #address - if need split
        if len(side_data.from_address) >= 60: # chars for font size 8
            #split to 2 line
            self.drawClippingString(side_data.from_address[:60], self.x(3.12*cm), self.y(11.5*cm), 9.6*cm, 0.5*cm)
            #if len(side_data.to_address[34:] >= ?)# need 3 line?
            self.drawClippingString(side_data.from_address[60:], self.x(2.03*cm), self.y(11*cm), 7.5*cm, 0.5*cm)
        else:
            self.drawClippingString(side_data.from_address, self.x(3.12*cm), self.y(11.5*cm), 5.1*cm, 0.5*cm)
            
        #zip_code
        zip_code = self.pdf.beginText()
        zip_code.setTextOrigin(self.x(9.77*cm), self.y(11.04*cm))
        zip_code.setFont('DejaVuSans', 10)
        zip_code.setCharSpace(8)
        zip_code.textLine(side_data.from_zip_code)
        zip_code.setCharSpace(0)
        self.pdf.drawText(zip_code)


        #to_down
        self.pdf.setFont('DejaVuSans', 8)
        #name
        self.drawClippingString(side_data.to_name, self.x(3.12*cm), self.y(3.3*cm), 9.4*cm, 0.5*cm)
        #address - if need split
        if len(side_data.to_address) >= 60: # 60chars for font size 8
            #split to 2 line
            self.drawClippingString(side_data.to_address[:60], self.x(3.2*cm), self.y(2.75*cm), 9.4*cm, 0.5*cm)
            #if len(side_data.to_address[34:] >= ?)# need 3 line?
            self.drawClippingString(side_data.to_address[60:], self.x(2*cm), self.y(2.28*cm), 7.5*cm, 0.5*cm)
        else:
            self.drawClippingString(side_data.to_address, self.x(3.2*cm), self.y(2.75*cm), 9.4*cm, 0.5*cm)
            
        #zip_code
        zip_code = self.pdf.beginText()
        zip_code.setTextOrigin(self.x(9.77*cm), self.y(2.18*cm))
        zip_code.setFont('DejaVuSans', 10)
        zip_code.setCharSpace(8)
        zip_code.textLine(side_data.to_zip_code)
        zip_code.setCharSpace(0)
        self.pdf.drawText(zip_code)
        
        #passport data
        self.pdf.setFontSize(8)
        self.drawClippingString2(side_data.passport_type , self.x(3.9*cm), self.y(9.6*cm), 8)
        self.drawClippingString2(side_data.passport_series , self.x(6.35*cm), self.y(9.6*cm), 4)
#.........这里部分代码省略.........
开发者ID:vovkd,项目名称:russian-post-receipts,代码行数:103,代码来源:f116_pdf_old.py

示例5: F116Pdf

# 需要导入模块: from reportlab.platypus.flowables import Image [as 别名]
# 或者: from reportlab.platypus.flowables.Image import drawOn [as 别名]
class F116Pdf(f116_pdf_old.F116PdfOld):
    def __init__(self, data, debug=False):
        super(F116Pdf, self).__init__(data, debug)

    def create_pdf_file(self, file_name, page_size=landscape(A4)):
        super(F116Pdf, self).create_pdf_file(file_name, page_size)
    
    def render_page1_image(self):
        A4_Width, A4_Height = A4
        self.im = Image(_self_path + '/'+u'side1.jpg',width=A4_Height, height=A4_Width)
        self.im.drawOn(self.pdf, self.x(0), self.y(0))
        self.pdf.line(A4_Height/2, 10, A4_Height/2, A4_Width-10)

    def render_page2_image(self):
        #TODO добыть картинку 2 стороны
        A4_Width, A4_Height = A4
        self.im = Image(_self_path + '/'+u'side2.jpg',width=A4_Height, height=A4_Width)
        self.im.drawOn(self.pdf, self.x(0), self.y(0))
        self.pdf.line(A4_Height/2, 10, A4_Height/2, A4_Width-10)

    def render_page1_oneside_data(self, side_data):
        self.pdf.setFont('DejaVuSans', 8)

        #money
        self.pdf.setFont('DejaVuSans', 12)
        self.pdf.drawString(self.x(0.9*cm), self.y(15.85*cm), side_data.sum + u" руб. 00 коп.")
        self.pdf.setFont('DejaVuSans', 10)
        self.pdf.drawString(self.x(2.20*cm), self.y(3.92*cm), side_data.sum)
        
        #to
        self.pdf.setFont('DejaVuSans', 8)
        #name
        self.drawClippingString2(side_data.to_name, self.x(1.7*cm), self.y(14.4*cm), 47)
        #address - if need split
        if len(side_data.to_address) >= 50: # 33chars for font size 8
            #split to 2 line
            self.drawClippingString2(side_data.to_address[:50], self.x(1.79*cm), self.y(13.85*cm), 50)
            #if len(side_data.to_address[34:] >= ?)# need 3 line?
            self.drawClippingString2(side_data.to_address[50:], self.x(0.9*cm), self.y(13.2*cm), 55)
        else:
            self.drawClippingString2(side_data.to_address, self.x(1.79*cm), self.y(13.85*cm), 50)
            
        #zip_code
        zip_code = self.pdf.beginText()
        zip_code.setTextOrigin(self.x(6.86*cm), self.y(12.55*cm))
        zip_code.setFont('DejaVuSans', 10)
        zip_code.setCharSpace(8)
        zip_code.textLine(side_data.to_zip_code)
        zip_code.setCharSpace(0)
        self.pdf.drawText(zip_code)
        
        #from
        #name
        self.drawClippingString2(side_data.from_name, self.x(2.0*cm), self.y(11.85*cm), 68)
        #address - if need split
        if len(side_data.from_address) >= 72: # chars for font size 8
            #split to 2 line
            self.drawClippingString2(side_data.from_address[:72], self.x(1.8*cm), self.y(11.12*cm), 72)
            #if len(side_data.to_address[34:] >= ?)# need 3 line?
            self.drawClippingString2(side_data.from_address[72:], self.x(0.9*cm), self.y(10.55*cm), 57)
        else:
            self.drawClippingString2(side_data.from_address, self.x(1.8*cm), self.y(11.12*cm), 72)
            
        #zip_code
        zip_code = self.pdf.beginText()
        zip_code.setTextOrigin(self.x(10.45*cm), self.y(10.6*cm))
        zip_code.setFont('DejaVuSans', 10)
        zip_code.setCharSpace(7.5)
        zip_code.textLine(side_data.from_zip_code)
        zip_code.setCharSpace(0)
        self.pdf.drawText(zip_code)


        #to_down
        self.pdf.setFont('DejaVuSans', 8)
        #name
        self.drawClippingString2(side_data.to_name, self.x(1.7*cm), self.y(3.12*cm), 73)
        #address - if need split
        if len(side_data.to_address) >= 60: # 60chars for font size 8
            #split to 2 line
            self.drawClippingString2(side_data.to_address[:60], self.x(1.8*cm), self.y(2.35*cm), 70)
            #if len(self.lside_data.to_address[34:] >= ?)# need 3 line?
            self.drawClippingString2(side_data.to_address[60:], self.x(0.9*cm), self.y(1.55*cm), 57)
        else:
            self.drawClippingString2(side_data.to_address, self.x(1.8*cm), self.y(2.35*cm), 77)
            
        #zip_code
        zip_code = self.pdf.beginText()
        zip_code.setTextOrigin(self.x(10.4*cm), self.y(1.6*cm))
        zip_code.setFont('DejaVuSans', 10)
        zip_code.setCharSpace(8)
        zip_code.textLine(side_data.to_zip_code)
        zip_code.setCharSpace(0)
        self.pdf.drawText(zip_code)
        
        #passport data
        self.pdf.setFontSize(8)
        self.drawClippingString2(side_data.passport_type , self.x(2.9*cm), self.y(9.18*cm), 8)
        self.drawClippingString2(side_data.passport_series , self.x(5.85*cm), self.y(9.18*cm), 4)
        self.drawClippingString2(side_data.passport_number , self.x(7.6*cm), self.y(9.18*cm), 6)
#.........这里部分代码省略.........
开发者ID:shantilabs,项目名称:russian-post-receipts,代码行数:103,代码来源:f116_pdf.py


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