本文整理汇总了Python中reportlab.platypus.frames.Frame类的典型用法代码示例。如果您正苦于以下问题:Python Frame类的具体用法?Python Frame怎么用?Python Frame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Frame类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: prepare_first_page
def prepare_first_page(canvas, document):
p1 = Paragraph(presentation.title, styles['Heading'])
p2 = Paragraph(
presentation.owner.get_full_name(), styles['SubHeading'])
avail_width = width - inch
avail_height = height - inch
w1, h1 = p1.wrap(avail_width, avail_height)
w2, h2 = p2.wrap(avail_width, avail_height)
f = Frame(
inch / 2,
inch / 2,
width - inch,
height - inch,
leftPadding=0,
bottomPadding=0,
rightPadding=0,
topPadding=0
)
f.addFromList([p1, p2], canvas)
document.pageTemplate.frames[0].height -= h1 + h2 + inch / 2
document.pageTemplate.frames[1].height -= h1 + h2 + inch / 2
canvas.saveState()
canvas.setStrokeColorRGB(0, 0, 0)
canvas.line(
width / 2, inch / 2, width / 2, height - inch - h1 - h2)
canvas.restoreState()
开发者ID:hanleybrand,项目名称:rooibos,代码行数:28,代码来源:viewers.py
示例2: drawCard
def drawCard(index, item):
p.saveState()
p.translate(0, height / 3 * (2 - index % 3))
# retrieve record while making sure it's accessible to presentation owner
record = Record.filter_one_by_access(presentation.owner, item.record.id)
if record:
image = get_image_for_record(record, presentation.owner, 800, 800, passwords)
if image:
p.drawImage(image, inch / 2, inch / 2, width=width / 2 - inch, height=height / 3 - inch,
preserveAspectRatio=True)
f = Frame(width / 2 + inch / 2, inch / 2,
width=width / 2 - inch, height=height / 3 - inch,
leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0)
data = []
data.append(getParagraph('%s/%s' % (index + 1, len(items)), styles['SlideNumber']))
values = item.get_fieldvalues(owner=request.user)
for value in values:
v = value.value if len(value.value) < 100 else value.value[:100] + '...'
v = remove_rels_from_a_tags(v)
data.append(getParagraph('<b>%s:</b> %s' % (value.resolved_label, v), styles['Data']))
annotation = item.annotation
if annotation:
data.append(getParagraph('<b>%s:</b> %s' % ('Annotation', annotation), styles['Data']))
data = filter(None, data)
f.addFromList(data, p)
if data:
p.setFont('Helvetica', 8)
p.setFillColorRGB(0, 0, 0)
p.drawRightString(width - inch / 2, inch / 2, '...')
p.restoreState()
开发者ID:eResearchSandpit,项目名称:rooibos,代码行数:35,代码来源:viewers.py
示例3: run
def run():
styles = getSampleStyleSheet()
styleN = styles['Normal']
styleH = styles['Heading1']
story = []
#for codeNames in code
story.append(Paragraph('I2of5', styleN))
story.append(I2of5(1234, barWidth = inch*0.02, checksum=0))
story.append(Paragraph('MSI', styleN))
story.append(MSI(1234))
story.append(Paragraph('Codabar', styleN))
story.append(Codabar("A012345B", barWidth = inch*0.02))
story.append(Paragraph('Code 11', styleN))
story.append(Code11("01234545634563"))
story.append(Paragraph('Code 39', styleN))
story.append(Standard39("A012345B%R"))
story.append(Paragraph('Extended Code 39', styleN))
story.append(Extended39("A012345B}"))
story.append(Paragraph('Code93', styleN))
story.append(Standard93("CODE 93"))
story.append(Paragraph('Extended Code93', styleN))
story.append(Extended93("[email protected]@K! Code 93 :-)")) #, barWidth=0.005 * inch))
story.append(Paragraph('Code 128', styleN))
c=Code128("AB-12345678") #, barWidth=0.005 * inch)
#print 'WIDTH =', (c.width / inch), 'barWidth =', (c.barWidth / inch)
#print 'LQ =', (c.lquiet / inch), 'RQ =', (c.rquiet / inch)
story.append(c)
story.append(Paragraph('USPS FIM', styleN))
story.append(FIM("A"))
story.append(Paragraph('USPS POSTNET', styleN))
story.append(POSTNET('78247-1043'))
story.append(Paragraph('USPS 4 State', styleN))
story.append(USPS_4State('01234567094987654321','01234567891'))
from reportlab.graphics.barcode import createBarcodeDrawing
story.append(Paragraph('EAN13', styleN))
bcd = createBarcodeDrawing('EAN13', value='123456789012')
story.append(bcd)
story.append(Paragraph('EAN8', styleN))
bcd = createBarcodeDrawing('EAN8', value='1234567')
story.append(bcd)
story.append(Paragraph('UPCA', styleN))
bcd = createBarcodeDrawing('UPCA', value='03600029145')
story.append(bcd)
story.append(Paragraph('USPS_4State', styleN))
bcd = createBarcodeDrawing('USPS_4State', value='01234567094987654321',routing='01234567891')
story.append(bcd)
story.append(Paragraph('Label Size', styleN))
story.append(XBox((2.0 + 5.0/8.0)*inch, 1 * inch, '1x2-5/8"'))
story.append(Paragraph('Label Size', styleN))
story.append(XBox((1.75)*inch, .5 * inch, '1/2x1-3/4"'))
c = Canvas('out.pdf')
f = Frame(inch, inch, 6*inch, 9*inch, showBoundary=1)
f.addFromList(story, c)
c.save()
print('saved out.pdf')
开发者ID:Aeium,项目名称:dotStudio,代码行数:58,代码来源:test.py
示例4: __init__
def __init__(self, filename, context, **kw):
BaseDocTemplate.__init__(self, filename, **kw)
self.toc_index = 0
self.main_frame_attr = {'x1': self.leftMargin,
'y1': self.bottomMargin,
'width': self.width,
'height': self.height,
'id':'normal',
'showBoundary': self.showBoundary}
# We keep the main frame reference to resize it during the build
self.main_frame = Frame(**self.main_frame_attr)
self.main_frame_change = False
template_attrs = {'id': 'now', 'frames': [self.main_frame],
'pagesize': kw['pagesize']}
page_template = PageTemplate(**template_attrs)
self.platypus_header_calculate = False
self.platypus_header_height = None
self.platypus_footer = None
self.context = context
self.addPageTemplates([page_template])
self.toc_high_level = self.context.toc_high_level
self.frame_attr = {'leftPadding': 0, 'bottomPadding': 6,
'rightPadding': 0, 'topPadding': 6,
'showBoundary': 0}
self.context = context
# calculate width available
self.width_available = self.width
self.width_available -= self.frame_attr['leftPadding']
self.width_available -= self.frame_attr['rightPadding']
开发者ID:Nabellaleen,项目名称:itools,代码行数:31,代码来源:doctemplate.py
示例5: write
def write(self, canvas):
"""Writes the frame to the
given canvas.
@param canvas: reportlab.pdfgen.canvas.Canvas
object that represents the canvas that the
container should write the frame to.
@return: None
"""
self._check_canvas(canvas)
self._check_start_point()
frame = Frame(self._x, self._y, self._width, self._height,
topPadding=0, bottomPadding=0)
frame.addFromList(self._components, canvas)
开发者ID:ti22restaurant,项目名称:PeonOrderSystem,代码行数:16,代码来源:ReceiptContainer.py
示例6: prepare_first_page
def prepare_first_page(canvas, document):
p1 = Paragraph(presentation.title, styles['Heading'])
p2 = Paragraph(presentation.owner.get_full_name(), styles['SubHeading'])
avail_width = width - inch
# TODO: determine if the complaint about height being undeclared is just pycharm or if its a problem
# if it is possibly a problem "it's better to be explicit" so refactor
avail_height = height - inch
w1, h1 = p1.wrap(avail_width, avail_height)
w2, h2 = p2.wrap(avail_width, avail_height)
f = Frame(inch / 2, inch / 2, width - inch, height - inch,
leftPadding=0, bottomPadding=0, rightPadding=0, topPadding=0)
f.addFromList([p1, p2], canvas)
document.pageTemplate.frames[0].height -= h1 + h2 + inch / 2
document.pageTemplate.frames[1].height -= h1 + h2 + inch / 2
canvas.saveState()
canvas.setStrokeColorRGB(0, 0, 0)
canvas.line(width / 2, inch / 2, width / 2, height - inch - h1 - h2)
canvas.restoreState()
开发者ID:eResearchSandpit,项目名称:rooibos,代码行数:20,代码来源:viewers.py
示例7: HeaderFooter
def HeaderFooter(canvas, doc):
canvas.saveState()
styleN = PS('nomal', fontName='Times-Roman', leading=9, fontSize=9)
P = Paragraph("This is a multi-line footer or header", styleN)
w, h = P.wrap(doc.width, doc.bottomMargin)
#print doc.width, doc.bottomMargin
#print w, h
#print dir(doc)
#print dir(canvas)
global pageNum
if doc.page < pageNum:
global ChapterName
ChapterName = 'Table of contents'
#print doc.page
#print ChapterName
pageNum = doc.page
if doc.page == 1:
footerMsg = []
footerMsg.append(Paragraph("Lei Yang", styleN))
footerMsg.append(Paragraph("Wei Gao", styleN))
footerMsg.append(Paragraph("XiangYu Dong", styleN))
footerMsg.append(Paragraph("Liang Chi", styleN))
footerMsg.append(Paragraph("Beijing ChaoYang, China", styleN))
canvas.line(2.5*cm, h+50, w+2.5*cm, h+50)
f = Frame(70, 2, 16*cm, 2.1*cm, showBoundary=0)
f.addFromList(footerMsg,canvas)
else:
P = Paragraph("User Guide", styleN)
w, h = P.wrap(doc.width, doc.bottomMargin)
P.drawOn(canvas, doc.leftMargin, h+789)
P = Paragraph(ChapterName, PS('nomal', fontName='Times-Roman', fontSize=9, alignment = TA_RIGHT, leading=9))
w, h = P.wrap(doc.width, doc.bottomMargin)
P.drawOn(canvas, doc.rightMargin, h+789)
P = Paragraph("Page %d" % doc.page, PS('nomal', fontName='Times-Roman', fontSize=9, alignment = 1))
w, h = P.wrap(doc.width, doc.bottomMargin)
P.drawOn(canvas, doc.leftMargin, h)
canvas.line(2.5*cm, h+780, w+2.5*cm, h+780)
canvas.restoreState()
开发者ID:leogao,项目名称:examples,代码行数:41,代码来源:generate_readme_pdf.py
示例8: myFirstPage
def myFirstPage(canvas, doc):
canvas.saveState()
canvas.setFont('Times-Bold', 16)
canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT-108, title)
canvas.setFont('Times-Roman', 9)
canvas.drawString(inch, 0.75 * inch, "Page %d - %s" % (doc.page, title))
frame_width = PAGE_WIDTH-200
hr = HRFlowable()
space = Spacer(frame_width, 20)
style = styles["Normal"]
qr_info = """<para rightIndent=10 leftIndent=20 alignment=right>This document is signed with the QR code shown on the right. Validate it using a Barcode Scanner."""
par = Paragraph(qr_info, style)
im = Image("qrcode.png", 101, 101)
pandi = ParagraphAndImage(par, im, xpad=3, ypad=30, side='right')
frame = Frame(100, 0, frame_width, 200, showBoundary=1)
frame.add(hr, canvas)
frame.add(space, canvas)
frame.add(pandi, canvas)
canvas.restoreState()
开发者ID:darg0001,项目名称:printable-digital-signature,代码行数:21,代码来源:generate_pdf.py
示例9: drawHeader
def drawHeader(self):
self.drawLogo()
styles = getSampleStyleSheet()
sN = styles['Normal']
sH = styles['Heading1']
sH.fontName = "OldEngMT"
sH.textColor = red
sH.leading = 18
sH.fontSize = 16
sN.fontSize = 9
sN.leading = 10
sN.alignment = sH.alignment = TA_CENTER
sN.spaceBefore = sH.spaceBefore = 0
sN.spaceAfter = sH.spaceAfter = 0
story = []
story.append(Paragraph("Holy Child Colleges of Butuan - Hospital", sH))
story.append(Paragraph("<b>(JP Esteves Clinical Laboratory)</b>", sN))
story.append(Paragraph("2nd St., Guingona Subd., " +
"Butuan City, Philippines", sN))
story.append(Paragraph("Tel. No.: +63 (85) 342-5186", sN))
story.append(Paragraph("Telefax No.: +63 (95) 342-397/225-6872", sN))
story.append(Paragraph("email: [email protected]", sN))
w, h = self.pagesize
f = Frame(0, h-self.topMargin, w, self.topMargin,
showBoundary=False)
f.addFromList(story, self.canv)
self.canv.setStrokeColor(red)
self.canv.setLineWidth(3)
self.canv.line(0.15*cm, h-self.topMargin,
w-0.15*cm, h-self.topMargin,
)
开发者ID:HCCB,项目名称:janus,代码行数:37,代码来源:reports.py
示例10: draw
def draw(self):
# set position for the frame
self.pos_x, self.pos_y = self._get_current_position(self.canv)
# XXX This is false, height=drawHeigh and drawHeight should take into
# account the frame padding
height = (self.drawHeight + self.frame_attrs['leftPadding'] +
self.frame_attrs['rightPadding'])
width = (self.drawWidth + self.frame_attrs['topPadding'] +
self.frame_attrs['bottomPadding'])
self.frame = Frame(self.pos_x, self.pos_y, width, height,
**self.frame_attrs)
if self.overflow:
# Hack, We lie by setting the new created frame as default frame
# of the doc template
# To avoid problems when calling keep_in_frame.wrap
# See platypus.flowables "def _listWrapOn"
_doctemplate = self.canv._doctemplate
# save state
current_frame = getattr(_doctemplate, 'frame', None)
_doctemplate.frame = self.frame
# Check if PTO is defined
if self.pto_trailer or self.pto_header:
ptocontainer = PTOContainer(self.div_story[:],
self.pto_trailer, self.pto_header)
ptocontainer.canv = self.canv
pto_size = ptocontainer.wrap(self.drawWidth, self.drawHeight)
# XXX Round the height to avoid problems with decimal
if int(pto_size[1]) > int(self.drawHeight):
pto_story = ptocontainer.split(self.drawWidth,
self.drawHeight)
self.frame.addFromList(pto_story, self.canv)
else:
self.frame.addFromList([self.keep_in_frame], self.canv)
else:
self.frame.addFromList([self.keep_in_frame], self.canv)
# restore state
if current_frame:
_doctemplate.frame = current_frame
else:
self.frame.addFromList(self.div_story[:], self.canv)
开发者ID:kennym,项目名称:itools,代码行数:42,代码来源:flowables.py
示例11: MySimpleDocTemplate
class MySimpleDocTemplate(BaseDocTemplate):
"""
The document template used for all PDF documents.
"""
def __init__(self, filename, context, **kw):
BaseDocTemplate.__init__(self, filename, **kw)
self.toc_index = 0
self.main_frame_attr = {'x1': self.leftMargin,
'y1': self.bottomMargin,
'width': self.width,
'height': self.height,
'id':'normal',
'showBoundary': self.showBoundary}
# We keep the main frame reference to resize it during the build
self.main_frame = Frame(**self.main_frame_attr)
self.main_frame_change = False
template_attrs = {'id': 'now', 'frames': [self.main_frame],
'pagesize': kw['pagesize']}
page_template = PageTemplate(**template_attrs)
self.platypus_header_calculate = False
self.platypus_header_height = None
self.platypus_footer = None
self.context = context
self.addPageTemplates([page_template])
self.toc_high_level = self.context.toc_high_level
self.frame_attr = {'leftPadding': 0, 'bottomPadding': 6,
'rightPadding': 0, 'topPadding': 6,
'showBoundary': 0}
self.context = context
# calculate width available
self.width_available = self.width
self.width_available -= self.frame_attr['leftPadding']
self.width_available -= self.frame_attr['rightPadding']
def beforePage(self):
self.context.current_page += 1
if self.context.has_header():
# HEADER
header = self.context.get_header()
self.canv.saveState()
# calculate height
if self.platypus_header_calculate is False:
element = header[0]
height = element.wrap(self.width_available, self.pagesize[1])[1]
height += self.frame_attr['topPadding']
height += self.frame_attr['bottomPadding']
self.platypus_header_height = height
height = self.platypus_header_height
# calculate coordinates
x = self.leftMargin
y = self.pagesize[1] - height
# resize margin if the frame is too big
if self.platypus_header_calculate is False:
if self.topMargin < height:
self.platypus_header_calculate = True
self.topMargin = height
# calculate self.width and self.height
self._calc()
# reset the main frame with new margin
self.main_frame_attr['x1'] = self.leftMargin
self.main_frame_attr['y1'] = self.bottomMargin
self.main_frame_attr['width'] = self.width
self.main_frame_attr['height'] = self.height
self.main_frame.__init__(**self.main_frame_attr)
else:
# frame is centered in top margin
y -= (self.topMargin - height) / 2
else:
# frame is centered in top margin
y -= (self.topMargin - height) / 2
# create a frame which will contain all platypus objects defined
# in the footer
fh = Frame(x, y, self.width_available, height, **self.frame_attr)
fh.addFromList(self.context.get_header_copy(), self.canv)
self.canv.restoreState()
if self.context.has_footer():
# FOOTER
footer = self.context.get_footer()
self.canv.saveState()
# calculate height
element = footer[0]
height = element.wrap(self.width_available, self.pagesize[1])[1]
height += self.frame_attr['topPadding']
height += self.frame_attr['bottomPadding']
# calculate coordinates
x = self.leftMargin
y = 0
#.........这里部分代码省略.........
开发者ID:Nabellaleen,项目名称:itools,代码行数:101,代码来源:doctemplate.py
示例12: Div
class Div(Flowable):
def __init__(self, story, height=None, width=None, pos_x=None, pos_y=None,
frame_attrs=freeze({}), attributes=freeze({}), pto_trailer=None,
pto_header=None):
Flowable.__init__(self)
# get on story
self.div_story = story
# set frame style
self.frame_attrs = {'leftPadding': 0, 'bottomPadding': 0,
'rightPadding': 0, 'topPadding': 0,
'showBoundary': 0}
# PTO initialisation
self.pto_trailer = pto_trailer
self.pto_header = pto_header
if frame_attrs is not None:
self.frame_attrs.update(frame_attrs)
for margin in ('topMargin', 'bottomMargin', 'leftMargin',
'rightMargin'):
if margin in self.frame_attrs:
del self.frame_attrs[margin]
border = self.frame_attrs['showBoundary']
if isinstance(border, ShowBoundaryValue):
border = border.width
if border:
for padding_attr in FRAME_PADDINGS_KEYS:
self.frame_attrs[padding_attr] += border
self.frame_width = width
# Overflow
# TODO to improve
self.keep_in_frame = None
style = attribute_style_to_dict(attributes.get((None, 'style'), ''))
self.overflow = style.get('overflow-y', None)
if self.overflow == 'hidden':
self.overflow = 'truncate'
else:
self.overflow = None
def draw(self):
# set position for the frame
self.pos_x, self.pos_y = self._get_current_position(self.canv)
# XXX This is false, height=drawHeigh and drawHeight should take into
# account the frame padding
height = (self.drawHeight + self.frame_attrs['leftPadding'] +
self.frame_attrs['rightPadding'])
width = (self.drawWidth + self.frame_attrs['topPadding'] +
self.frame_attrs['bottomPadding'])
self.frame = Frame(self.pos_x, self.pos_y, width, height,
**self.frame_attrs)
if self.overflow:
# Hack, We lie by setting the new created frame as default frame
# of the doc template
# To avoid problems when calling keep_in_frame.wrap
# See platypus.flowables "def _listWrapOn"
_doctemplate = self.canv._doctemplate
# save state
current_frame = getattr(_doctemplate, 'frame', None)
_doctemplate.frame = self.frame
# Check if PTO is defined
if self.pto_trailer or self.pto_header:
ptocontainer = PTOContainer(self.div_story[:],
self.pto_trailer, self.pto_header)
ptocontainer.canv = self.canv
pto_size = ptocontainer.wrap(self.drawWidth, self.drawHeight)
# XXX Round the height to avoid problems with decimal
if int(pto_size[1]) > int(self.drawHeight):
pto_story = ptocontainer.split(self.drawWidth,
self.drawHeight)
self.frame.addFromList(pto_story, self.canv)
else:
self.frame.addFromList([self.keep_in_frame], self.canv)
else:
self.frame.addFromList([self.keep_in_frame], self.canv)
# restore state
if current_frame:
_doctemplate.frame = current_frame
else:
self.frame.addFromList(self.div_story[:], self.canv)
def wrap(self, availWidth, availHeight):
canv = self.canv
if self.overflow:
if self.keep_in_frame is None:
# FIXME if the availHeight is very small
# We consider that there is no enough space
# and we calculate the real size of the flowables
if availHeight <= 0:
width, height = self._get_real_size(availWidth)
else:
width, height = availWidth, availHeight
# Dirty hack, get the current frame height and use it
#.........这里部分代码省略.........
开发者ID:kennym,项目名称:itools,代码行数:101,代码来源:flowables.py
示例13: build_pdf
def build_pdf(self, response):
cleaned_data = self.filterset.form.cleaned_data
impresso = cleaned_data['impresso']
fs = int(impresso.fontsize)
if cleaned_data['fontsize']:
fs = int(cleaned_data['fontsize'])
stylesheet = StyleSheet1()
stylesheet.add(ParagraphStyle(name='pronome_style',
fontName="Helvetica",
fontSize=fs * 0.8,
leading=fs))
stylesheet.add(ParagraphStyle(name='nome_style',
fontName="Helvetica-Bold",
fontSize=fs,
leading=fs * 1.3))
stylesheet.add(ParagraphStyle(name='endereco_style',
fontName="Helvetica",
fontSize=fs * 0.9,
leading=fs))
pagesize = (float(impresso.largura_pagina) * cm,
float(impresso.altura_pagina) * cm)
ms = pagesize[1] - float(impresso.margem_superior) * cm
me = float(impresso.margem_esquerda) * cm
ae = float(impresso.alturaetiqueta) * cm
le = float(impresso.larguraetiqueta) * cm
el = float(impresso.entre_linhas) * cm
ec = float(impresso.entre_colunas) * cm
col = float(impresso.colunasfolha)
row = float(impresso.linhasfolha)
cr = int(col * row)
p = canvas.Canvas(response, pagesize=pagesize)
if impresso.rotate:
p.translate(pagesize[1], 0)
p.rotate(90)
i = -1
for contato in self.object_list.all():
i += 1
if i != 0 and i % cr == 0:
p.showPage()
if impresso.rotate:
p.translate(pagesize[1], 0)
p.rotate(90)
q = floor(i / col) % row
r = i % int(col)
l = me + r * ec + r * le
b = ms - (q + 1) * ae - q * el
f = Frame(l, b, le, ae,
leftPadding=fs / 3,
bottomPadding=fs / 3,
topPadding=fs / 3,
rightPadding=fs / 3,
showBoundary=0)
# f.drawBoundary(p)
f.addFromList(self.createParagraphs(contato, stylesheet), p)
p.showPage()
p.save()
开发者ID:cmjatai,项目名称:cmj,代码行数:73,代码来源:reports.py
示例14: beforePage
def beforePage(self):
self.context.current_page += 1
if self.context.has_header():
# HEADER
header = self.context.get_header()
self.canv.saveState()
# calculate height
if self.platypus_header_calculate is False:
element = header[0]
height = element.wrap(self.width_available, self.pagesize[1])[1]
height += self.frame_attr['topPadding']
height += self.frame_attr['bottomPadding']
self.platypus_header_height = height
height = self.platypus_header_height
# calculate coordinates
x = self.leftMargin
y = self.pagesize[1] - height
# resize margin if the frame is too big
if self.platypus_header_calculate is False:
if self.topMargin < height:
self.platypus_header_calculate = True
self.topMargin = height
# calculate self.width and self.height
self._calc()
# reset the main frame with new margin
self.main_frame_attr['x1'] = self.leftMargin
self.main_frame_attr['y1'] = self.bottomMargin
self.main_frame_attr['width'] = self.width
self.main_frame_attr['height'] = self.height
self.main_frame.__init__(**self.main_frame_attr)
else:
# frame is centered in top margin
y -= (self.topMargin - height) / 2
else:
# frame is centered in top margin
y -= (self.topMargin - height) / 2
# create a frame which will contain all platypus objects defined
# in the footer
fh = Frame(x, y, self.width_available, height, **self.frame_attr)
fh.addFromList(self.context.get_header_copy(), self.canv)
self.canv.restoreState()
if self.context.has_footer():
# FOOTER
footer = self.context.get_footer()
self.canv.saveState()
# calculate height
element = footer[0]
height = element.wrap(self.width_available, self.pagesize[1])[1]
height += self.frame_attr['topPadding']
height += self.frame_attr['bottomPadding']
# calculate coordinates
x = self.leftMargin
y = 0
# resize margin if the frame is too big
if self.bottomMargin < height:
self.bottomMargin = height
# calculate self.width and self.height
self._calc()
# reset the main frame with new margin
self.main_frame_attr['x1'] = self.leftMargin
self.main_frame_attr['y1'] = self.bottomMargin
self.main_frame_attr['width'] = self.width
self.main_frame_attr['height'] = self.height
self.main_frame.__init__(**self.main_frame_attr)
else:
# frame is centered in bottom margin
y = (self.bottomMargin - height) / 2
# create a frame which will contain all platypus objects defined
# in the footer
ff = Frame(x, y, self.width_available, height, **self.frame_attr)
ff.addFromList(self.context.get_footer_copy(), self.canv)
self.canv.restoreState()
开发者ID:Nabellaleen,项目名称:itools,代码行数:81,代码来源:doctemplate.py
示例15: atPage
def atPage(self, name, pseudopage, declarations):
c = self.c
data = {}
name = name or "body"
pageBorder = None
if declarations:
result = self.ruleset([self.selector('*')], declarations)
# print "@PAGE", name, pseudopage, declarations, result
if declarations:
data = result[0].values()[0]
pageBorder = data.get("-pdf-frame-border", None)
if name in c.templateList:
log.warn(self.c.warning("template '%s' has already been defined", name))
if "-pdf-page-size" in data:
c.pageSize = xhtml2pdf.default.PML_PAGESIZES.get(str(data["-pdf-page-size"]).lower(), c.pageSize)
isLandscape = False
if "size" in data:
size = data["size"]
# print size, c.pageSize
if type(size) is not types.ListType:
size = [size]
sizeList = []
for value in size:
valueStr = str(value).lower()
if type(value) is types.TupleType:
sizeList.append(getSize(value))
elif valueStr == "landscape":
isLandscape = True
elif valueStr in xhtml2pdf.default.PML_PAGESIZES:
c.pageSize = xhtml2pdf.default.PML_PAGESIZES[valueStr]
else:
log.warn(c.warning("Unknown size value for @page"))
if len(sizeList) == 2:
c.pageSize = sizeList
if isLandscape:
c.pageSize = landscape(c.pageSize)
for prop in ("margin-top", "margin-left", "margin-right", "margin-bottom",
"top", "left", "right", "bottom", "width", "height"):
if prop in data:
c.frameList.append(self._pisaAddFrame(name, data, first=True, border=pageBorder, size=c.pageSize))
break
# self._drawing = PmlPageDrawing(self._pagesize)
#if not c.frameList:
# c.warning("missing frame definitions for template")
# return {}, {}
# Frames have to be calculated after we know the pagesize
frameList = []
staticList = []
for fname, static, border, x, y, w, h, fdata in c.frameList:
#fix frame sizing problem.
if static:
x, y, w, h = getFrameDimensions(fdata, c.pageSize[0], c.pageSize[1])
x, y, w, h = getCoords(x, y, w, h, c.pageSize)
if w <= 0 or h <= 0:
log.warn(self.c.warning("Negative width or height of frame. Check @frame definitions."))
frame = Frame(
x, y, w, h,
id=fname,
leftPadding=0,
rightPadding=0,
bottomPadding=0,
topPadding=0,
showBoundary=border or pageBorder)
if static:
frame.pisaStaticStory = []
c.frameStatic[static] = [frame] + c.frameStatic.get(static, [])
staticList.append(frame)
else:
frameList.append(frame)
background = data.get("background-image", None)
if background:
background = self.c.getFile(background)
# print background
# print frameList
if not frameList:
# print 999
log.warn(c.warning("missing explicit frame definition for content or just static frames"))
fname, static, border, x, y, w, h, data = self._pisaAddFrame(name, data, first=True, border=pageBorder, size=c.pageSize)
x, y, w, h = getCoords(x, y, w, h, c.pageSize)
if w <= 0 or h <= 0:
log.warn(c.warning("Negative width or height of frame. Check @page definitions."))
frameList.append(Frame(
x, y, w, h,
id=fname,
leftPadding=0,
rightPadding=0,
bottomPadding=0,
topPadding=0,
showBoundary=border or pageBorder))
#.........这里部分代码省略.........
开发者ID:AndrewJHart,项目名称:xhtml2pdf,代码行数:101,代码来源:context.py
示例16: atPage
def atPage(self, name, pseudopage, declarations):
c = self.c
data = {}
name = name or "body"
pageBorder = None
if declarations:
result = self.ruleset([self.selector('*')], declarations)
if declarations:
data = list(result[0].values())[0]
pageBorder = data.get("-pdf-frame-border", None)
if name in c.templateList:
log.warning(self.c.warning("template '%s' has already been defined", name))
if "-pdf-page-size" in data:
c.pageSize = xhtml2pdf.default.PML_PAGESIZES.get(str(data["-pdf-page-size"]).lower(), c.pageSize)
isLandscape = False
if "size" in data:
size = data["size"]
if type(size) is not list:
size = [size]
sizeList = []
for value in size:
valueStr = str(value).lower()
if type(value) is tuple:
sizeList.append(getSize(value))
elif valueStr == "landscape":
isLandscape = True
elif valueStr in xhtml2pdf.default.PML_PAGESIZES:
c.pageSize = xhtml2pdf.default.PML_PAGESIZES[valueStr]
else:
log.warning(c.warning("Unknown size value for @page"))
if len(sizeList) == 2:
c.pageSize = tuple(sizeList)
if isLandscape:
c.pageSize = landscape(c.pageSize)
padding_top = self._getFromData(data, 'padding-top', 0, getSize)
padding_left = self._getFromData(data, 'padding-left', 0, getSize)
padding_right = self._getFromData(data, 'padding-right', 0, getSize)
padding_bottom = self._getFromData(data, 'padding-bottom', 0, getSize)
border_color = self._getFromData(data, ('border-top-color', 'border-bottom-color',\
'border-left-color', 'border-right-color'), None, getColor)
border_width = self._getFromData(data, ('border-top-width', 'border-bottom-width',\
'border-left-width', 'border-right-width'), 0, getSize)
for prop in ("margin-top", "margin-left", "margin-right", "margin-bottom",
"top", "left", "right", "bottom", "width", "height"):
if prop in data:
c.frameList.append(self._pisaAddFrame(name, data, first=True, border=pageBorder, size=c.pageSize))
break
# Frames have to be calculated after we know the pagesize
frameList = []
staticList = []
for fname, static, border, x, y, w, h, fdata in c.frameList:
fpadding_top = self._getFromData(fdata, 'padding-top', padding_top, getSize)
fpadding_left = self._getFromData(fdata, 'padding-left', padding_left, getSize)
fpadding_right = self._getFromData(fdata, 'padding-right', padding_right, getSize)
fpadding_bottom = self._getFromData(fdata, 'padding-bottom', padding_bottom, getSize)
fborder_color = self._getFromData(fdata, ('border-top-color', 'border-bottom-color',\
'border-left-color', 'border-right-color'), border_color, getColor)
fborder_width = self._getFromData(fdata, ('border-top-width', 'border-bottom-width',\
'border-left-width', 'border-right-width'), border_width, getSize)
if border or pageBorder:
frame_border = ShowBoundaryValue()
else:
frame_border = ShowBoundaryValue(color=fborder_color, width=fborder_width)
#fix frame sizing problem.
if static:
x, y, w, h = getFrameDimensions(fdata, c.pageSize[0], c.pageSize[1])
x, y, w, h = getCoords(x, y, w, h, c.pageSize)
if w <= 0 or h <= 0:
log.warning(self.c.warning("Negative width or height of frame. Check @frame definitions."))
frame = Frame(
x, y, w, h,
id=fname,
leftPadding=fpadding_left,
rightPadding=fpadding_right,
bottomPadding=fpadding_bottom,
topPadding=fpadding_top,
showBoundary=frame_border)
if static:
frame.pisaStaticStory = []
c.frameStatic[static] = [frame] + c.frameStatic.get(static, [])
staticList.append(frame)
else:
frameList.append(frame)
background = data.get("background-image", None)
if background:
#should be relative to the css file
#.........这里部分代码省略.........
开发者ID:AntycSolutions,项目名称:xhtml2pdf,代码行数:101,代码来源:context.py
示例17: run
def run():
styles = getSampleStyleSheet()
styleN = styles["Normal"]
styleH = styles["Heading1"]
story = []
# for codeNames in code
story.append(Paragraph("I2of5", styleN))
story.append(I2of5(1234, barWidth=inch * 0.02, checksum=0))
story.append(Paragraph("MSI", styleN))
story.append(MSI(1234))
story.append(Paragraph("Codabar", styleN))
story.append(Codabar("A012345B", barWidth=inch * 0.02))
story.append(Paragraph("Code 11", styleN))
story.append(Code11("01234545634563"))
story.append(Paragraph("Code 39", styleN))
story.append(Standard39("A012345B%R"))
story.append(Paragraph("Extended Code 39", styleN))
story.append(Extended39("A012345B}"))
story.append(Paragraph("Code93", styleN))
story.append(Standard93("CODE 93"))
story.append(Paragraph("Extended Code93", styleN))
story.append(Extended93("[email protected]@K! Code 93 :-)")) # , barWidth=0.005 * inch))
story.append(Paragraph("Code 128", styleN))
c = Code128("AB-12345678") # , barWidth=0.005 * inch)
# print 'WIDTH =', (c.width / inch), 'barWidth =', (c.barWidth / inch)
# print 'LQ =', (c.lquiet / inch), 'RQ =', (c.rquiet / inch)
story.append(c)
story.append(Paragraph("USPS FIM", styleN))
story.append(FIM("A"))
story.append(Paragraph("USPS POSTNET", styleN))
story.append(POSTNET("78247-1043"))
story.append(Paragraph("USPS 4 State", styleN))
story.append(USPS_4State("01234567094987654321", "01234567891"))
from reportlab.graphics.barcode import createBarcodeDrawing
story.append(Paragraph("EAN13", styleN))
bcd = createBarcodeDrawing("EAN13", value="123456789012")
story.append(bcd)
story.append(Paragraph("EAN8", styleN))
bcd = createBarcodeDrawing("EAN8", value="1234567")
story.append(bcd)
story.append(Paragraph(&quo
|
请发表评论