本文整理匯總了Python中reportlab.platypus.flowables.Image._restrictSize方法的典型用法代碼示例。如果您正苦於以下問題:Python Image._restrictSize方法的具體用法?Python Image._restrictSize怎麽用?Python Image._restrictSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類reportlab.platypus.flowables.Image
的用法示例。
在下文中一共展示了Image._restrictSize方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: fill_sender
# 需要導入模塊: from reportlab.platypus.flowables import Image [as 別名]
# 或者: from reportlab.platypus.flowables.Image import _restrictSize [as 別名]
def fill_sender(self):
"""Fills sender identity"""
from reportlab.platypus.flowables import Image
from core.pdf.utils import Paragraph
# Sender identity
sender_paragraphs = []
if self.invoice_base.current_revision.sender:
sender_paragraphs.append(Paragraph(self.invoice_base.current_revision.sender, self.style['Small']))
sender_paragraphs.append(Paragraph(self.invoice_base.tenant.name, self.style['Small']))
if self.invoice_base.current_revision.sender_address:
sender_paragraphs.append(Paragraph(u'\n'.join(self.invoice_base.current_revision.sender_address.get_formatted()), self.style['Small']))
# Add layout table if logo or paragraphs
if self.invoice_base.tenant.logo_cache:
logo = Image(self.invoice_base.tenant.logo_cache)
logo_width, logo_height = logo._restrictSize(50*mm, 20*mm)
self.table(
[[logo, sender_paragraphs]],
(logo_width + 4*mm, None),
self.style['LayoutTable'],
rowHeights=(20*mm,)
)
else:
for paragraph in sender_paragraphs:
self.append(paragraph)
示例2: fill
# 需要導入模塊: from reportlab.platypus.flowables import Image [as 別名]
# 或者: from reportlab.platypus.flowables.Image import _restrictSize [as 別名]
def fill(self):
from django.template.defaultfilters import date as format_date, floatformat
from reportlab.platypus.flowables import Image
from core.pdf.utils import Paragraph
from invoicing import currency_format
# Sender frame
# Sender identity
sender_paragraphs = []
if self.invoice_base.current_revision.sender:
sender_paragraphs.append(Paragraph(self.invoice_base.current_revision.sender, self.style['Small']))
sender_paragraphs.append(Paragraph(self.invoice_base.tenant.name, self.style['Small']))
if self.invoice_base.current_revision.sender_address:
sender_paragraphs.append(Paragraph(u'\n'.join(self.invoice_base.current_revision.sender_address.get_formatted()), self.style['Small']))
# Add layout table if logo or paragraphs
if self.invoice_base.tenant.logo_cache:
logo = Image(self.invoice_base.tenant.logo_cache)
logo_width, logo_height = logo._restrictSize(50 * mm, 20 * mm)
self.table(
[[logo, sender_paragraphs]],
(logo_width + 4 * mm, None),
self.style['LayoutTable'],
rowHeights=(20 * mm,)
)
else:
for paragraph in sender_paragraphs:
self.append(paragraph)
# Billing address frame
self.next_frame()
if self.invoice_base.current_revision.contact:
self.p(self.invoice_base.current_revision.contact.get_full_name(upper_name=True), style=self.style['Address'])
if self.invoice_base.current_revision.organization:
self.p(self.invoice_base.current_revision.organization.corporate_name, style=self.style['Address'])
if self.invoice_base.current_revision.billing_address:
self.p(u'\n'.join(self.invoice_base.current_revision.billing_address.get_formatted()), style=self.style['Address'])
# Delivery address frame
self.next_frame()
if self.invoice_base.current_revision.contact:
self.p(self.invoice_base.current_revision.contact.get_full_name(upper_name=True), style=self.style['Address'])
if self.invoice_base.current_revision.organization:
self.p(self.invoice_base.current_revision.organization.corporate_name, style=self.style['Address'])
if self.invoice_base.current_revision.delivery_address:
self.p(u'\n'.join(self.invoice_base.current_revision.delivery_address.get_formatted()), style=self.style['Address'])
# Rest of the report
self.next_frame()
invoice_reference = pgettext('date', 'Undefined') if getattr(self.invoice_base, 'has_temporary_reference', None) else self.invoice_base.reference
self.table([[
' '.join([unicode(self.invoice_base.RECORD_NAME).upper(), invoice_reference]),
format_date(self.invoice_base.current_revision.invoicing_date, 'DATE_FORMAT')
]], (12 * cm, 5 * cm), style=self.style['InvoiceBaseReferencesTable'])
self.spacer()
rows = [[
pgettext('table-headers', 'Description'),
pgettext('table-headers', 'Qty'),
pgettext('table-headers', 'Unit price (excl. tax)'),
pgettext('table-headers', 'Tax'),
pgettext('table-headers', 'Total (excl. tax)')
]]
for item in self.invoice_base.current_revision.line_items:
rows.append([
item.description,
floatformat(item.quantity, -2),
currency_format(item.unit_price),
'{0:.2%}'.format(item.tax.rate),
currency_format(item.total_price, self.invoice_base.current_revision.currency.symbol)
])
col_widths = (85 * mm, 20 * mm, 20 * mm, 20 * mm, 25 * mm)
self.table(rows, col_widths, repeatRows=1, style=self.style['InvoiceBaseItemsTable'])
self.spacer()
rows = [[
_('TOTAL (excl. tax)'),
currency_format(self.invoice_base.sub_total, self.invoice_base.current_revision.currency.symbol)
]]
for tax in self.invoice_base.taxes_amounts:
rows.append([
'%(tax_name)s (%(tax_rate)s)' % {
'tax_name': tax.get('name'),
'tax_rate': '{0:.2%}'.format(tax.get('rate'))
},
currency_format(tax.get('amount'), self.invoice_base.current_revision.currency.symbol)
])
rows.append([
_('TOTAL (incl. tax)'),
currency_format(self.invoice_base.amount, self.invoice_base.current_revision.currency.symbol)
])
col_widths = (None, 25 * mm)
self.start_keeptogether()
self.table(rows, col_widths, hAlign='RIGHT', style=self.style['InvoiceBaseSummaryTable'])
self.end_keeptogether()
# Legal notices
self.spacer()
self.start_keeptogether()
if self.invoice_base.is_quotation():
self.p(_("Valid until %(quotation_validity)s") % {
#.........這裏部分代碼省略.........