本文整理匯總了Python中reportlab.platypus.flowables.Image.hAlign方法的典型用法代碼示例。如果您正苦於以下問題:Python Image.hAlign方法的具體用法?Python Image.hAlign怎麽用?Python Image.hAlign使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類reportlab.platypus.flowables.Image
的用法示例。
在下文中一共展示了Image.hAlign方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: add_image
# 需要導入模塊: from reportlab.platypus.flowables import Image [as 別名]
# 或者: from reportlab.platypus.flowables.Image import hAlign [as 別名]
def add_image(self, src, width, height, align=CENTER, caption=None):
if src.split(".")[-1] in ["png", "PNG"]:
try:
f = open(src, 'rb')
data = StringIO(f.read())
except:
return
else:
img = Image(data, width, height)
f.close()
else:
img = Image(src, width, height)
img.hAlign = align
if caption:
caption_p = Paragraph(caption, self.theme.paragraph_centered)
image_table = Table([[img], [caption_p]], width)
image_table.setStyle(TableStyle([('ALIGN',(-1,-1),(-1,-1),
'CENTER')]))
self.add(image_table)
else:
self.add(img)
示例2: __init__
# 需要導入模塊: from reportlab.platypus.flowables import Image [as 別名]
# 或者: from reportlab.platypus.flowables.Image import hAlign [as 別名]
#.........這裏部分代碼省略.........
style = [
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
('FONT', (1, 0), (1, -1), "Helvetica-Bold", dictOptions["taille_texte_labels_totaux"]),
('FONT', (2, 0), (2, -1), "Helvetica-Bold", dictOptions["taille_texte_montants_totaux"]),
('GRID', (2, 0), (2, 0), 0.25, colors.black),
('GRID', (2, 1), (2, 1), 0.25, colors.black),
('GRID', (2, 2), (2, 2), 0.25, colors.black),
('ALIGN', (1, 0), (1, -1), 'RIGHT'),
('ALIGN', (2, 0), (2, -1), 'CENTRE'),
('BACKGROUND', (2, 2), (2, 2), couleurFond),
('SPAN', (0, 0), (0, -1)),
]
if mode == "facture" and len(listeMessages) > 0 :
#style.append( ('BACKGROUND', (0, 0), (0, 0), couleurFondActivite) )
style.append( ('FONT', (0, 0), (0, -1), "Helvetica", 8) )
style.append( ('VALIGN', (0, 0), (0, -1), 'TOP') )
tableau = Table(dataTableau, largeursColonnes, rowHeights=[18, 18, None])
tableau.setStyle(TableStyle(style))
story.append(tableau)
# ------------------------- PRELEVEMENTS --------------------
if dictOptions.has_key("afficher_avis_prelevements") and dictValeur.has_key("prelevement") :
if dictValeur["prelevement"] != None and dictOptions["afficher_avis_prelevements"] == True :
paraStyle = ParagraphStyle(name="intro",
fontName="Helvetica",
fontSize=8,
leading=11,
spaceBefore=2,
spaceafter=2,
alignment=1,
backColor=couleurFondActivite,
)
story.append(Spacer(0,20))
story.append(Paragraph(u"<para align='center'><i>%s</i></para>" % dictValeur["prelevement"], paraStyle))
# Texte conclusion
if dictOptions["texte_conclusion"] != "" :
story.append(Spacer(0,20))
paraStyle = ParagraphStyle(name="conclusion",
fontName="Helvetica",
fontSize=dictOptions["taille_texte_conclusion"],
leading=14,
spaceBefore=0,
spaceafter=0,
leftIndent=5,
rightIndent=5,
alignment=dictOptions["alignement_texte_conclusion"],
backColor=ConvertCouleurWXpourPDF(dictOptions["couleur_fond_conclusion"]),
borderColor=ConvertCouleurWXpourPDF(dictOptions["couleur_bord_conclusion"]),
borderWidth=0.5,
borderPadding=5,
)
texte = dictValeur["texte_conclusion"].replace("\\n", "<br/>")
if dictOptions["style_texte_conclusion"] == 0 : texte = u"<para>%s</para>" % texte
if dictOptions["style_texte_conclusion"] == 1 : texte = u"<para><i>%s</i></para>" % texte
if dictOptions["style_texte_conclusion"] == 2 : texte = u"<para><b>%s</b></para>" % texte
if dictOptions["style_texte_conclusion"] == 3 : texte = u"<para><i><b>%s</b></i></para>" % texte
story.append(Paragraph(texte, paraStyle))
# Image signature
if dictOptions["image_signature"] != "" :
cheminImage = dictOptions["image_signature"]
if os.path.isfile(cheminImage) :
img = Image(cheminImage)
largeur, hauteur = int(img.drawWidth * 1.0 * dictOptions["taille_image_signature"] / 100.0), int(img.drawHeight * 1.0 * dictOptions["taille_image_signature"] / 100.0)
if largeur > CADRE_CONTENU[2] or hauteur > CADRE_CONTENU[3] :
raise Exception(_(u"L'image de signature est trop grande. Veuillez diminuer sa taille avec le parametre Taille."))
img.drawWidth, img.drawHeight = largeur, hauteur
if dictOptions["alignement_image_signature"] == 0 : img.hAlign = "LEFT"
if dictOptions["alignement_image_signature"] == 1 : img.hAlign = "CENTER"
if dictOptions["alignement_image_signature"] == 2 : img.hAlign = "RIGHT"
story.append(Spacer(0,20))
story.append(img)
# Saut de page
story.append(PageBreak())
# Finalisation du PDF
## try :
doc.build(story)
## except Exception, err :
## print "Erreur dans ouverture PDF :", err
## if "Permission denied" in err :
## dlg = wx.MessageDialog(None, _(u"Noethys ne peut pas créer le PDF.\n\nVeuillez vérifier qu'un autre PDF n'est pas déjà ouvert en arrière-plan..."), _(u"Erreur d'édition"), wx.OK | wx.ICON_ERROR)
## dlg.ShowModal()
## dlg.Destroy()
## return
# Ouverture du PDF
if ouverture == True :
FonctionsPerso.LanceFichierExterne(nomDoc)
示例3: add_image
# 需要導入模塊: from reportlab.platypus.flowables import Image [as 別名]
# 或者: from reportlab.platypus.flowables.Image import hAlign [as 別名]
def add_image(self, src, width, height, align=CENTER):
img = Image(src, width, height)
img.hAlign = align
self.add(img)
示例4: image
# 需要導入模塊: from reportlab.platypus.flowables import Image [as 別名]
# 或者: from reportlab.platypus.flowables.Image import hAlign [as 別名]
def image(self, name, width, height, halign='CENTER'):
im = Image(name, width=width, height=height)
im.hAlign = halign
self._store_flowable(im)
示例5: createUrgentCoverPage
# 需要導入模塊: from reportlab.platypus.flowables import Image [as 別名]
# 或者: from reportlab.platypus.flowables.Image import hAlign [as 別名]
def createUrgentCoverPage(page_size=PAGE_SIZE_LETTER,
total_pages=1,
recipient_name='',
recipient_phone='',
recipient_fax='',
sender_name='',
sender_phone='',
sender_fax='',
sender_email='',
regarding='',
message='',
preserve_formatting=False,
output=None):
s = getSampleStyleSheet()
story = []
i = Image(os.path.join(prop.image_dir, 'other', 'urgent_title.png'), width=424, height=92)
i.hAlign = 'LEFT'
story.append(i)
story.append(Spacer(1, inch))
story.append(HRFlowable(width='100%', color='black'))
ps = ParagraphStyle(name='normal',
fontName='Times-Roman',
#fontName='STSong-Light',
#fontName='UMing',
fontSize=12)
recipient_name_label = Paragraph("To:", ps)
recipient_name_text = Paragraph(escape(recipient_name[:64]), ps)
recipient_fax_label = Paragraph("Fax:", ps)
recipient_fax_text = Paragraph(escape(recipient_fax[:64]), ps)
recipient_phone_label = Paragraph("Phone:", ps)
recipient_phone_text = Paragraph(escape(recipient_phone[:64]), ps)
sender_name_label = Paragraph("From:", ps)
sender_name_text = Paragraph(escape(sender_name[:64]), ps)
sender_phone_label = Paragraph("Phone:", ps)
sender_phone_text = Paragraph(escape(sender_phone[:64]), ps)
sender_email_label = Paragraph("Email:", ps)
sender_email_text = Paragraph(escape(sender_email[:64]), ps)
regarding_label = Paragraph("Regarding:", ps)
regarding_text = Paragraph(escape(regarding[:128]), ps)
date_time_label = Paragraph("Date:", ps)
date_time_text = Paragraph(strftime("%a, %d %b %Y %H:%M:%S (%Z)", localtime()), ps)
total_pages_label = Paragraph("Total Pages:", ps)
total_pages_text = Paragraph("%d" % total_pages, ps)
data = [[recipient_name_label, recipient_name_text],
[recipient_fax_label, recipient_fax_text],
['', ''],
[sender_name_label, sender_name_text],
[sender_phone_label, sender_phone_text],
[sender_email_label, sender_email_text],
['', ''],
[date_time_label, date_time_text],
[total_pages_label, total_pages_text],
[regarding_label, regarding_text],]
LIST_STYLE = TableStyle([#('LINEABOVE', (0,0), (-1,0), 2, colors.black),
#('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
#('LINEBELOW', (0,-1), (-1,-1), 2, colors.black),
('ALIGN', (1,1), (-1,-1), 'RIGHT'),
('VALIGN', (0, 0), (-1, -1), 'TOP'),
])
story.append(Table(data, style=LIST_STYLE))
story.append(HRFlowable(width='100%', color='black'))
if message:
MSG_STYLE = TableStyle([#('LINEABOVE', (0,0), (-1,0), 2, colors.black),
#('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
#('LINEBELOW', (0,-1), (-1,-1), 2, colors.black),
('ALIGN', (1,1), (-1,-1), 'RIGHT'),
('VALIGN', (0, 0), (-1, -1), 'TOP'),
#('SPAN', (-2, 1), (-1, -1)),
])
#story.append(HRFlowable(width='100%', color='black'))
story.append(Spacer(1, 0.5*inch))
# if preserve_formatting:
# message = '\n'.join(message[:2048].splitlines()[:32])
#
# data = [#[Paragraph("Comments/Notes:", ps), ''],
# [Preformatted(escape(message), ps)],]
# else:
# data = [#[Paragraph("Comments/Notes:", ps), ''],
# [Paragraph(escape(message[:2048]), ps), ''],]
#
# #story.append(HRFlowable(width='100%', color='black'))
#.........這裏部分代碼省略.........