本文整理汇总了Python中reportlab.platypus.paragraph.Paragraph.drawOn方法的典型用法代码示例。如果您正苦于以下问题:Python Paragraph.drawOn方法的具体用法?Python Paragraph.drawOn怎么用?Python Paragraph.drawOn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.platypus.paragraph.Paragraph
的用法示例。
在下文中一共展示了Paragraph.drawOn方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ReferenceText
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import drawOn [as 别名]
class ReferenceText(IndexingFlowable):
"""Fakery to illustrate how a reference would work if we could
put it in a paragraph."""
def __init__(self, textPattern, targetKey):
self.textPattern = textPattern
self.target = targetKey
self.paraStyle = ParagraphStyle('tmp')
self._lastPageNum = None
self._pageNum = -999
self._para = None
def beforeBuild(self):
self._lastPageNum = self._pageNum
def notify(self, kind, stuff):
if kind == 'Target':
(key, pageNum) = stuff
if key == self.target:
self._pageNum = pageNum
def wrap(self, availWidth, availHeight):
text = self.textPattern % self._lastPageNum
self._para = Paragraph(text, self.paraStyle)
return self._para.wrap(availWidth, availHeight)
def drawOn(self, canvas, x, y, _sW=0):
self._para.drawOn(canvas, x, y, _sW)
示例2: test3
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import drawOn [as 别名]
def test3(self):
from reportlab.pdfgen.canvas import Canvas
aW=307
styleSheet = getSampleStyleSheet()
bt = styleSheet['BodyText']
btj = ParagraphStyle('bodyText1j',parent=bt,alignment=TA_JUSTIFY)
p=Paragraph("""<a name='top'/>Subsequent pages test pageBreakBefore, frameBreakBefore and
keepTogether attributes. Generated at 1111. The number in brackets
at the end of each paragraph is its position in the story. llllllllllllllllllllllllll
bbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccc ddddddddddddddddddddd eeeeyyy""",btj)
w,h=p.wrap(aW,1000)
canv=Canvas('test_platypus_paragraph_just.pdf',pagesize=(aW,h))
i=len(canv._code)
p.drawOn(canv,0,0)
ParaCode=canv._code[i:]
canv.saveState()
canv.setLineWidth(0)
canv.setStrokeColorRGB(1,0,0)
canv.rect(0,0,aW,h)
canv.restoreState()
canv.showPage()
canv.save()
from reportlab import rl_config
x = rl_config.paraFontSizeHeightOffset and '50' or '53.17'
good = ['q', '1 0 0 1 0 0 cm', 'q', 'BT 1 0 0 1 0 '+x+' Tm 3.59 Tw 12 TL /F1 10 Tf 0 0 0 rg (Subsequent pages test pageBreakBefore, frameBreakBefore and) Tj T* 0 Tw .23 Tw (keepTogether attributes. Generated at 1111. The number in brackets) Tj T* 0 Tw .299167 Tw (at the end of each paragraph is its position in the story. llllllllllllllllllllllllll) Tj T* 0 Tw 66.9 Tw (bbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccc) Tj T* 0 Tw (ddddddddddddddddddddd eeeeyyy) Tj T* ET', 'Q', 'Q']
ok= ParaCode==good
assert ok, "\nParaCode=%r\nexpected=%r" % (ParaCode,good)
示例3: beforeDrawPage
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import drawOn [as 别名]
def beforeDrawPage(self,canvas,doc):
canvas.setFont(serif_font,10)
canvas.setLineWidth(0)
#header
canvas.line(header_margin_hor, page_height - header_margin_vert, page_width - header_margin_hor, page_height - header_margin_vert )
if pdfstyles.show_page_header:
canvas.saveState()
canvas.resetTransforms()
canvas.translate(header_margin_hor, page_height - header_margin_vert - 0.1*cm)
p = Paragraph(self.title, text_style())
p.canv = canvas
p.wrap(page_width - header_margin_hor*2.5, page_height) # add an extra 0.5 margin to have enough space for page number
p.drawPara()
canvas.restoreState()
canvas.drawRightString(page_width - header_margin_hor, page_height - header_margin_vert + 0.1 * cm, "%d" % doc.page)
#Footer
canvas.saveState()
canvas.setFont(serif_font,8)
canvas.line(footer_margin_hor, footer_margin_vert, page_width - footer_margin_hor, footer_margin_vert )
if pdfstyles.show_page_footer:
p = Paragraph(formatter.cleanText(pagefooter, escape=False), text_style())
p.canv = canvas
w,h = p.wrap(page_width - header_margin_hor*2.5, page_height)
p.drawOn(canvas, footer_margin_hor, footer_margin_vert - 10 - h)
canvas.restoreState()
示例4: __list_format
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import drawOn [as 别名]
def __list_format(canvas, doc):
canvas.saveState()
building_style = ParagraphStyle(name='building_title',
fontSize=__FONT_SIZE__)
t = u'%s<br/>Data afișării: %s<br/>Luna: %s' % (doc.habitam_building.name,
doc.habitam_display,
doc.habitam_month)
p = Paragraph(t, building_style)
p.wrapOn(canvas, 5 * cm, 2 * cm)
p.drawOn(canvas, .5 * cm, __HEIGHT__ - 1.7 * cm)
habitam_brand(canvas, __WIDTH__, __HEIGHT__)
canvas.restoreState()
示例5: test3
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import drawOn [as 别名]
def test3(self):
'''compare CJK splitting in some edge cases'''
from reportlab.pdfgen.canvas import Canvas
from reportlab.platypus.paragraph import Paragraph
from reportlab.lib.styles import ParagraphStyle
from reportlab.pdfbase import pdfmetrics
from reportlab.lib.enums import TA_LEFT
sty = ParagraphStyle('A')
sty.fontSize = 15
sty.leading = sty.fontSize*1.2
sty.fontName = 'Courier'
sty.alignment = TA_LEFT
sty.wordWrap = 'CJK'
p0=Paragraph('ABCDEFGHIJKL]N',sty)
p1=Paragraph('AB<font color="red">C</font>DEFGHIJKL]N',sty)
canv = Canvas('test_platypus_paragraph_cjk3.pdf')
ix = len(canv._code)
aW = pdfmetrics.stringWidth('ABCD','Courier',15)
w,h=p0.wrap(aW,1000000)
y = canv._pagesize[1]-72-h
p0.drawOn(canv,72,y)
w,h=p1.wrap(aW,1000000)
y -= h+10
p1.drawOn(canv,72,y)
w,h=p0.wrap(aW*0.25-2,1000000)
y -= h+10
p0.drawOn(canv,72,y)
w,h=p1.wrap(aW/4.-2,1000000)
y -= h+10
p1.drawOn(canv,72,y)
assert canv._code[ix:]==['q', '1 0 0 1 72 697.8898 cm', 'q', '0 0 0 rg', 'BT 1 0 0 1 0 57 Tm /F2 15 Tf 18 TL (ABCD) Tj T* (EFGH) Tj T* (IJKL]) Tj T* (N) Tj T* ET', 'Q', 'Q', 'q', '1 0 0 1 72 615.8898 cm', 'q', 'BT 1 0 0 1 0 57 Tm 18 TL /F2 15 Tf 0 0 0 rg (AB) Tj 1 0 0 rg (C) Tj 0 0 0 rg (D) Tj T* (EFGH) Tj T* (IJKL]) Tj T* (N) Tj T* ET', 'Q', 'Q', 'q', '1 0 0 1 72 353.8898 cm', 'q', '0 0 0 rg', 'BT 1 0 0 1 0 237 Tm /F2 15 Tf 18 TL (A) Tj T* (B) Tj T* (C) Tj T* (D) Tj T* (E) Tj T* (F) Tj T* (G) Tj T* (H) Tj T* (I) Tj T* (J) Tj T* (K) Tj T* (L) Tj T* (]) Tj T* (N) Tj T* ET', 'Q', 'Q', 'q', '1 0 0 1 72 91.88976 cm', 'q', 'BT 1 0 0 1 0 237 Tm 18 TL /F2 15 Tf 0 0 0 rg (A) Tj T* (B) Tj T* 1 0 0 rg (C) Tj T* 0 0 0 rg (D) Tj T* (E) Tj T* (F) Tj T* (G) Tj T* (H) Tj T* (I) Tj T* (J) Tj T* (K) Tj T* (L) Tj T* (]) Tj T* (N) Tj T* ET', 'Q', 'Q']
canv.showPage()
canv.save()
示例6: HeaderFooter
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import drawOn [as 别名]
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()
示例7: test0
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import drawOn [as 别名]
def test0(self):
"A basic document drawing some strings"
c = Canvas(outputfile('test_multibyte_jpn.pdf'))
c.setFont('Helvetica', 30)
c.drawString(100,700, 'Japanese Font Support')
c.setStrokeColor(colors.red)
#unicode font automatically supplies the encoding
pdfmetrics.registerFont(UnicodeCIDFont('HeiseiMin-W3'))
msg = u'\u6771\u4EAC : Unicode font, unicode input'
self.hDraw(c, msg, 'HeiseiMin-W3', 100, 600)
msg = u'\u6771\u4EAC : Unicode font, utf8 input'.encode('utf8')
self.hDraw(c, msg, 'HeiseiMin-W3', 100, 575)
# now try verticals - this is broken, not sure how to make it
# work in post Unicode world.
pdfmetrics.registerFont(CIDFont('HeiseiMin-W3','90ms-RKSJ-V'))
c.setFont('HeiseiMin-W3-90ms-RKSJ-V', 16)
c.drawString(450, 650, '\223\214\213\236 vertical Shift-JIS')
height = c.stringWidth('\223\214\213\236 vertical Shift-JIS', 'HeiseiMin-W3-90ms-RKSJ-V', 16)
c.rect(450-8,650,16,-height)
pdfmetrics.registerFont(CIDFont('HeiseiMin-W3','EUC-V'))
c.setFont('HeiseiMin-W3-EUC-V', 16)
c.drawString(475, 650, '\xC5\xEC\xB5\xFE vertical EUC')
height = c.stringWidth('\xC5\xEC\xB5\xFE vertical EUC', 'HeiseiMin-W3-EUC-V', 16)
c.rect(475-8,650,16,-height)
from reportlab.platypus.paragraph import Paragraph
from reportlab.lib.styles import ParagraphStyle
jStyle = ParagraphStyle('jtext',
fontName='HeiseiMin-W3',
fontSize=12,
wordWrap="CJK"
)
gatwickText = '\xe3\x82\xac\xe3\x83\x88\xe3\x82\xa6\xe3\x82\xa3\xe3\x83\x83\xe3\x82\xaf\xe7\xa9\xba\xe6\xb8\xaf\xe3\x81\xa8\xe9\x80\xa3\xe7\xb5\xa1\xe9\x80\x9a\xe8\xb7\xaf\xe3\x81\xa7\xe7\x9b\xb4\xe7\xb5\x90\xe3\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3\x82\x8b\xe5\x94\xaf\xe4\xb8\x80\xe3\x81\xae\xe3\x83\x9b\xe3\x83\x86\xe3\x83\xab\xe3\x81\xa7\xe3\x81\x82\xe3\x82\x8b\xe5\xbd\x93\xe3\x83\x9b\xe3\x83\x86\xe3\x83\xab\xe3\x81\xaf\xe3\x80\x81\xe8\xa1\x97\xe3\x81\xae\xe4\xb8\xad\xe5\xbf\x83\xe9\x83\xa8\xe3\x81\x8b\xe3\x82\x8930\xe5\x88\x86\xe3\x81\xae\xe5\xa0\xb4\xe6\x89\x80\xe3\x81\xab\xe3\x81\x94\xe3\x81\x96\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe5\x85\xa8\xe5\xae\xa2\xe5\xae\xa4\xe3\x81\xab\xe9\xab\x98\xe9\x80\x9f\xe3\x82\xa4\xe3\x83\xb3\xe3\x82\xbf\xe3\x83\xbc\xe3\x83\x8d\xe3\x83\x83\xe3\x83\x88\xe7\x92\xb0\xe5\xa2\x83\xe3\x82\x92\xe5\xae\x8c\xe5\x82\x99\xe3\x81\x97\xe3\x81\xa6\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe3\x83\x95\xe3\x82\xa1\xe3\x83\x9f\xe3\x83\xaa\xe3\x83\xbc\xe3\x83\xab\xe3\x83\xbc\xe3\x83\xa0\xe3\x81\xaf5\xe5\x90\x8d\xe6\xa7\x98\xe3\x81\xbe\xe3\x81\xa7\xe3\x81\x8a\xe6\xb3\x8a\xe3\x82\x8a\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe3\x81\xbe\xe3\x81\x9f\xe3\x80\x81\xe3\x82\xa8\xe3\x82\xb0\xe3\x82\xbc\xe3\x82\xaf\xe3\x83\x86\xe3\x82\xa3\xe3\x83\x96\xe3\x83\xab\xe3\x83\xbc\xe3\x83\xa0\xe3\x81\xae\xe3\x81\x8a\xe5\xae\xa2\xe6\xa7\x98\xe3\x81\xaf\xe3\x80\x81\xe3\x82\xa8\xe3\x82\xb0\xe3\x82\xbc\xe3\x82\xaf\xe3\x83\x86\xe3\x82\xa3\xe3\x83\x96\xe3\x83\xa9\xe3\x82\xa6\xe3\x83\xb3\xe3\x82\xb8\xe3\x82\x92\xe3\x81\x94\xe5\x88\xa9\xe7\x94\xa8\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe4\xba\x8b\xe5\x89\x8d\xe3\x81\xab\xe3\x81\x94\xe4\xba\x88\xe7\xb4\x84\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x82\x8b\xe3\x82\xbf\xe3\x82\xa4\xe3\x83\xa0\xe3\x83\x88\xe3\x82\xa5\xe3\x83\x95\xe3\x83\xa9\xe3\x82\xa4\xe3\x83\xbb\xe3\x83\x91\xe3\x83\x83\xe3\x82\xb1\xe3\x83\xbc\xe3\x82\xb8\xe3\x81\xab\xe3\x81\xaf\xe3\x80\x81\xe7\xa9\xba\xe6\xb8\xaf\xe3\x81\xae\xe9\xa7\x90\xe8\xbb\x8a\xe6\x96\x99\xe9\x87\x91\xe3\x81\x8c\xe5\x90\xab\xe3\x81\xbe\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82'
gatwickText2= '\xe3\x82\xac\xe3\x83\x88\xe3\x82\xa6\xe3\x82\xa3\xe3\x83\x83\xe3\x82\xaf<font color=red>\xe7\xa9\xba\xe6\xb8\xaf\xe3\x81\xa8\xe9\x80\xa3\xe7\xb5\xa1\xe9\x80\x9a\xe8\xb7\xaf\xe3\x81\xa7\xe7\x9b\xb4\xe7\xb5\x90</font>\xe3\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3\x82\x8b\xe5\x94\xaf\xe4\xb8\x80\xe3\x81\xae\xe3\x83\x9b\xe3\x83\x86\xe3\x83\xab\xe3\x81\xa7\xe3\x81\x82\xe3\x82\x8b\xe5\xbd\x93\xe3\x83\x9b\xe3\x83\x86\xe3\x83\xab\xe3\x81\xaf\xe3\x80\x81\xe8\xa1\x97\xe3\x81\xae\xe4\xb8\xad\xe5\xbf\x83\xe9\x83\xa8\xe3\x81\x8b\xe3\x82\x8930\xe5\x88\x86\xe3\x81\xae\xe5\xa0\xb4\xe6\x89\x80\xe3\x81\xab\xe3\x81\x94\xe3\x81\x96\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe5\x85\xa8\xe5\xae\xa2\xe5\xae\xa4\xe3\x81\xab\xe9\xab\x98\xe9\x80\x9f\xe3\x82\xa4\xe3\x83\xb3\xe3\x82\xbf\xe3\x83\xbc\xe3\x83\x8d\xe3\x83\x83\xe3\x83\x88<link fg="blue" href="http://www.reportlab.com">\xe7\x92\xb0\xe5\xa2\x83\xe3\x82\x92\xe5\xae\x8c\xe5\x82\x99</link>\xe3\x81\x97\xe3\x81\xa6<u>\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99</u>\xe3\x80\x82\xe3\x83\x95\xe3\x82\xa1\xe3\x83\x9f\xe3\x83\xaa\xe3\x83\xbc\xe3\x83\xab\xe3\x83\xbc\xe3\x83\xa0\xe3\x81\xaf5\xe5\x90\x8d\xe6\xa7\x98\xe3\x81\xbe\xe3\x81\xa7\xe3\x81\x8a\xe6\xb3\x8a\xe3\x82\x8a\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe3\x81\xbe\xe3\x81\x9f\xe3\x80\x81\xe3\x82\xa8\xe3\x82\xb0\xe3\x82\xbc\xe3\x82\xaf\xe3\x83\x86\xe3\x82\xa3\xe3\x83\x96\xe3\x83\xab\xe3\x83\xbc\xe3\x83\xa0\xe3\x81\xae\xe3\x81\x8a\xe5\xae\xa2\xe6\xa7\x98\xe3\x81\xaf\xe3\x80\x81\xe3\x82\xa8\xe3\x82\xb0\xe3\x82\xbc\xe3\x82\xaf\xe3\x83\x86\xe3\x82\xa3\xe3\x83\x96\xe3\x83\xa9\xe3\x82\xa6\xe3\x83\xb3\xe3\x82\xb8\xe3\x82\x92\xe3\x81\x94\xe5\x88\xa9\xe7\x94\xa8\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82\xe4\xba\x8b\xe5\x89\x8d\xe3\x81\xab\xe3\x81\x94\xe4\xba\x88\xe7\xb4\x84\xe3\x81\x84\xe3\x81\x9f\xe3\x81\xa0\xe3\x81\x91\xe3\x82\x8b\xe3\x82\xbf\xe3\x82\xa4\xe3\x83\xa0\xe3\x83\x88\xe3\x82\xa5\xe3\x83\x95\xe3\x83\xa9\xe3\x82\xa4\xe3\x83\xbb\xe3\x83\x91\xe3\x83\x83\xe3\x82\xb1\xe3\x83\xbc\xe3\x82\xb8\xe3\x81\xab\xe3\x81\xaf\xe3\x80\x81\xe7\xa9\xba\xe6\xb8\xaf\xe3\x81\xae\xe9\xa7\x90\xe8\xbb\x8a\xe6\x96\x99\xe9\x87\x91\xe3\x81\x8c\xe5\x90\xab\xe3\x81\xbe\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x8a\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82'
c.setFont('HeiseiMin-W3', 12)
jPara = Paragraph(gatwickText, jStyle)
jPara.wrap(300, 200)
jPara.drawOn(c, 100, 220)
jPara = Paragraph(gatwickText2, jStyle)
jPara.wrap(300, 200)
jPara.drawOn(c, 100, 320)
c.setFillColor(colors.purple)
tx = c.beginText(100, 200)
tx.setFont('Helvetica', 12)
tx.textLines("""This document shows sample output in Japanese
from the Reportlab PDF library. This page shows the two fonts
available and tests our ability to measure the width of glyphs
in both horizontal and vertical writing, with proportional and
fixed-width characters. The red boxes should be the same width
(or height) as the character strings they surround.
The next pages show more samples and information.
""")
c.drawText(tx)
c.setFont('Helvetica',10)
c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber())
c.showPage()
c.setFont('Helvetica', 30)
c.drawString(100,700, 'Japanese TrueType Font Support')
msg = u'\u6771\u4EAC : Unicode font'.encode('utf8')
msg2 = u'utf8 input 0123456789 ABCDEF'.encode('utf8')
from reportlab.pdfbase.ttfonts import TTFont
try:
msmincho = TTFont('MS Mincho','msmincho.ttc',subfontIndex=0,asciiReadable=0)
fn = ' file=msmincho.ttc subfont 0'
except:
try:
msmincho = TTFont('MS Mincho','msmincho.ttf',asciiReadable=0)
fn = 'file=msmincho.ttf'
except:
#Ubuntu - works on Lucid Lynx if xpdf-japanese installed
try:
msmincho = TTFont('MS Mincho','ttf-japanese-mincho.ttf')
fn = 'file=msmincho.ttf'
except:
msmincho = None
if msmincho is None:
c.setFont('Helvetica', 12)
c.drawString(100,600, 'Cannot find msmincho.ttf or msmincho.ttc')
else:
#.........这里部分代码省略.........
示例8: testUtf8Canvas
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import drawOn [as 别名]
def testUtf8Canvas(self):
"""Verify canvas declared as utf8 autoconverts.
This assumes utf8 input. It converts to the encoding of the
underlying font, so both text lines APPEAR the same."""
c = Canvas(outputfile('test_pdfbase_encodings_utf8.pdf'))
c.drawString(100,700, testUTF8)
# Set a font with UTF8 encoding
c.setFont('Vera', 12)
# This should pass the UTF8 through unchanged
c.drawString(100,600, testUTF8)
# and this should convert from Unicode to UTF8
c.drawString(100,500, testUni)
# now add a paragraph in Latin-1 in the latin-1 style
p = Paragraph(testUTF8, style=self.styNormal, encoding="utf-8")
w, h = p.wrap(150, 100)
p.drawOn(c, 100, 400) #3
c.rect(100,300,w,h)
# now add a paragraph in UTF-8 in the UTF-8 style
p2 = Paragraph(testUTF8, style=self.styTrueType, encoding="utf-8")
w, h = p2.wrap(150, 100)
p2.drawOn(c, 300, 400) #4
c.rect(100,300,w,h)
# now add a paragraph in Unicode in the latin-1 style
p3 = Paragraph(testUni, style=self.styNormal)
w, h = p3.wrap(150, 100)
p3.drawOn(c, 100, 300)
c.rect(100,300,w,h)
# now add a paragraph in Unicode in the UTF-8 style
p4 = Paragraph(testUni, style=self.styTrueType)
p4.wrap(150, 100)
p4.drawOn(c, 300, 300)
c.rect(300,300,w,h)
# now a graphic
d1 = Drawing(400,50)
d1.add(Ellipse(200,25,200,12.5, fillColor=None))
d1.add(String(200,25,testUTF8, textAnchor='middle', encoding='utf-8'))
d1.drawOn(c, 100, 150)
# now a graphic in utf8
d2 = Drawing(400,50)
d2.add(Ellipse(200,25,200,12.5, fillColor=None))
d2.add(String(200,25,testUTF8, fontName='Vera', textAnchor='middle', encoding='utf-8'))
d2.drawOn(c, 100, 100)
# now a graphic in Unicode with T1 font
d3 = Drawing(400,50)
d3.add(Ellipse(200,25,200,12.5, fillColor=None))
d3.add(String(200,25,testUni, textAnchor='middle'))
d3.drawOn(c, 100, 50)
# now a graphic in Unicode with TT font
d4 = Drawing(400,50)
d4.add(Ellipse(200,25,200,12.5, fillColor=None))
d4.add(String(200,25,testUni, fontName='Vera', textAnchor='middle'))
d4.drawOn(c, 100, 0)
extracted = extractText(c.getCurrentPageContent())
self.assertEquals(extracted[0], expectedCp1252)
self.assertEquals(extracted[1], extracted[2])
#self.assertEquals(subsetToUnicode(self.vera, extracted[1]), testUni)
c.save()
示例9: makePDF
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import drawOn [as 别名]
#.........这里部分代码省略.........
"textLeading" : 15,
"entryHeight" : entryHeight,
"glyphPointSize" : 48,
"glyphEntryHeight" : glyphEntryHeight,
"minorLine" : minorLine,
"majorLine" : majorLine,
"glyphSpacing" : glyphSpacing,
}
basicStyle = ParagraphStyle("BasicReport")
basicStyle.fontName = settings["regularFont"]
basicStyle.fontSize = settings["textPointSize"]
basicStyle.leading = settings["textLeading"]
pdf = canvas.Canvas(path, pagesize=pageSize)
_drawTemplate(pdf, settings)
flatResults = []
currentTop = startTop
head = [u"Fonts tested:", ]
for font in fonts:
head.append(u"%s: %s" % (font.info.postscriptFullName, font.path))
flatResults.append(("head", head))
flatResults.append(("blank line", None))
for name in names:
flatResults.append(("line", majorLine))
flatResults.append(("note", name))
flatResults.append(("line", majorLine))
flatResults.append(("blank line", None))
flatResults.append(("blank line", None))
flatResults.append(("glyph", name))
lines = []
for tag, content in flatResults:
if tag == "line":
lines.append((currentTop, content))
elif tag == "blank line":
currentTop -= blankLineHeight
elif tag == "head":
entities = [
("&", "&"),
("<", "<"),
(">", ">"),
('"', """),
("'", "'"),
]
pdf.setFillColorRGB(0, 0, 0)
textObject = pdf.beginText(margin, currentTop - 13)
textObject.setFont(settings["boldFont"], settings["textPointSize"], leading=12)
start = textObject.getY()
for line in content:
if line != content[0]:
textObject.setFont(settings["regularFont"], settings["textPointSize"], leading=12)
for b, a in entities:
content = line.replace(b, a)
textObject.textLine(line)
end = textObject.getY()
pdf.drawText(textObject)
currentTop -= (start - end)
elif tag == "note":
entities = [
("&", "&"),
("<", "<"),
(">", ">"),
('"', """),
("'", "'"),
]
for b, a in entities:
content = content.replace(b, a)
p = Paragraph(content, basicStyle)
w, h = p.wrap(settings["resultsWidth"], 5000)
rH = h + ((h / settings["textLeading"]) * 5)
if rH > 20:
rH -= ((rH / 20) - 1) * 5
if currentTop - (rH + glyphEntryHeight + blankLineHeight * 2) < margin:
lines = _finishPage(pdf, lines, settings)
_drawTemplate(pdf, settings)
currentTop = startTop
_drawHighlightBox(pdf, currentTop, rH, settings)
p.drawOn(pdf, settings["resultsLeft"], currentTop - h - 3)
_drawLabel(pdf, currentTop, "glyph:", settings)
currentTop -= rH
else:
# make sure that we have room to start all this
if currentTop - glyphEntryHeight < margin:
lines = _finishPage(pdf, lines, settings)
_drawTemplate(pdf, settings)
currentTop = startTop
_drawGlyphs(pdf, content, currentTop, fonts, settings)
currentTop -= glyphEntryHeight
for top, weight in lines:
_drawLine(pdf, top, weight, settings)
pdf.save()
示例10: makePDF
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import drawOn [as 别名]
def makePDF(names, fonts, pageSize, path):
width, height = pageSize
margin = 36
resultsLeft = 100
resultsRight = width - margin
startTop = height - 75
blankLineHeight = 20
entryHeight = 20
glyphEntryHeight = 48
minorLine = .3
majorLine = 1
glyphSpacing = 10
settings = {
"date" : time.asctime(),
"width" : width,
"height" : height,
"margin" : margin,
"labelRight" : 90,
"resultsLeft" : resultsLeft,
"resultsRight" : resultsRight,
"resultsWidth" : resultsRight - resultsLeft,
"labelWidth" : width - margin - resultsLeft,
"contentWidth" : width - (margin * 2),
"startTop" : startTop,
"regularFont" : "Helvetica",
"boldFont" : "Helvetica-Bold",
"textPointSize" : 10,
"textLeading" : 15,
"entryHeight" : entryHeight,
"glyphPointSize" : 36,
"glyphEntryHeight" : glyphEntryHeight,
"minorLine" : minorLine,
"majorLine" : majorLine,
"glyphSpacing" : glyphSpacing,
}
basicStyle = ParagraphStyle("BasicReport")
basicStyle.fontName = settings["regularFont"]
basicStyle.fontSize = settings["textPointSize"]
basicStyle.leading = settings["textLeading"]
pdf = canvas.Canvas(path, pagesize=pageSize)
_drawTemplate(pdf, settings)
flatResults = []
currentTop = startTop
for name in names:
flatResults.append(("line", majorLine))
flatResults.append(("note", name))
flatResults.append(("line", majorLine))
flatResults.append(("blank line", None))
flatResults.append(("glyph", name))
flatResults.append(("blank line", None))
lines = []
for tag, content in flatResults:
if tag == "line":
lines.append((currentTop, content))
elif tag == "blank line":
currentTop -= blankLineHeight
elif tag == "note":
entities = [
("&", "&"),
("<", "<"),
(">", ">"),
('"', """),
("'", "'"),
]
for b, a in entities:
content = content.replace(b, a)
p = Paragraph(content, basicStyle)
w, h = p.wrap(settings["resultsWidth"], 5000)
rH = h + ((h / settings["textLeading"]) * 5)
if rH > 20:
rH -= ((rH / 20) - 1) * 5
if currentTop - rH < margin:
lines = _finishPage(pdf, lines, settings)
_drawTemplate(pdf, settings)
currentTop = startTop
_drawHighlightBox(pdf, currentTop, rH, settings)
p.drawOn(pdf, settings["resultsLeft"], currentTop - h - 3)
_drawLabel(pdf, currentTop, "Glyph", settings)
currentTop -= rH
else:
# make sure that we have room to start all this
if currentTop - glyphEntryHeight < margin:
lines = _finishPage(pdf, lines, settings)
_drawTemplate(pdf, settings)
#.........这里部分代码省略.........