本文整理汇总了Python中reportlab.lib.testutils.outputfile函数的典型用法代码示例。如果您正苦于以下问题:Python outputfile函数的具体用法?Python outputfile怎么用?Python outputfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了outputfile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test0
def test0(self, isFast=0):
"""Hello World, on a rectangular background.
The rectangle's fillColor is yellow.
The string's fillColor is red.
"""
reportlab.rl_config.shapeChecking = not isFast
pdfPath = outputfile('test_graphics_speed_fast.pdf')
c = Canvas(pdfPath)
t0 = time.time()
d = Drawing(400, 200)
num = 100
for i in range(num):
pc = Pie()
pc.x = 150
pc.y = 50
pc.data = [10,20,30,40,50,60]
pc.labels = ['a','b','c','d','e','f']
pc.slices.strokeWidth=0.5
pc.slices[3].popout = 20
pc.slices[3].strokeWidth = 2
pc.slices[3].strokeDashArray = [2,2]
pc.slices[3].labelRadius = 1.75
pc.slices[3].fontColor = colors.red
d.add(pc)
d.drawOn(c, 80, 500)
t1 = time.time()
result = 'drew %d pie charts in %0.4f' % (num, t1 - t0)
open(outputfile('test_graphics_speed_test%s.log' % (isFast+1)), 'w').write(result)
示例2: test1
def test1(self):
c=canvas.Canvas(outputfile('test_pdfgen_obscure.pdf'))
c.setViewerPreference('PrintScaling','None')
c.setViewerPreference('HideToolbar','true')
c.setViewerPreference('HideMenubar','true')
c.addPageLabel(0, prefix="Front")
c.addPageLabel(1, style='ROMAN_LOWER', start=2)
c.addPageLabel(8, style='ARABIC')
# (These are fixes for missing pages)
c.addPageLabel(11, style='ARABIC',start=6)
c.addPageLabel(17, style='ARABIC', start=14)
c.addPageLabel(21, style='ARABIC', start=22)
#check that duplicate page start will not cause sort error in python 3.x
c.addPageLabel(98, style='ROMAN_LOWER', start=99, prefix='r')
c.addPageLabel(98, style='ARABIC', start=99, prefix='A')
c.addPageLabel(99, style='LETTERS_UPPER')
c.addPageLabel(102, prefix="Back",start=1)
# Make some (mostly) empty pages
for i in range(113):
c.drawString(100, 100, 'This is page '+str(i))
c.showPage()
# Output the PDF
c.save()
示例3: test1
def test1(self):
"This makes several special paragraphs."
# Build story.
story = []
styleSheet = getSampleStyleSheet()
bt = styleSheet["BodyText"]
btN = ParagraphStyle("BodyTextTTNone", parent=bt, textTransform="none")
btL = ParagraphStyle("BodyTextTTLower", parent=bt, textTransform="lowercase")
btU = ParagraphStyle("BodyTextTTUpper", parent=bt, textTransform="uppercase")
btC = ParagraphStyle("BodyTextTTCapitalize", parent=bt, textTransform="capitalize")
story.append(Paragraph("""This should be ORDINARY text.""", style=bt))
story.append(Paragraph("""This should be ORDINARY text.""", style=btN))
story.append(Paragraph("""This should be LOWER text.""", style=btL))
story.append(Paragraph("""This should be upper text.""", style=btU))
story.append(Paragraph("""This should be cAPITALIZED text.""", style=btC))
story.append(Paragraph("""T<i>hi</i>s shoul<font color="red">d b</font>e <b>ORDINARY</b> text.""", style=bt))
story.append(Paragraph("""T<i>hi</i>s shoul<font color="red">d b</font>e <b>ORDINARY</b> text.""", style=btN))
story.append(Paragraph("""T<i>hi</i>s shoul<font color="red">d b</font>e <b>LOWER</b> text.""", style=btL))
story.append(Paragraph("""T<i>hi</i>s shoul<font color="red">d b</font>e <b>upper</b> text.""", style=btU))
story.append(
Paragraph("""T<i>hi</i>s shoul<font color="red">d b</font>e <b>cAPITALIZED</b> text.""", style=btC)
)
doc = MyDocTemplate(outputfile("test_platypus_specialparagraphs.pdf"))
doc.multiBuild(story)
示例4: testVisible
def testVisible(self):
"Makes a document with extra text - should export and distill"
c = Canvas(outputfile('test_pdfbase_postscript_visible.pdf'))
c.setPageCompression(0)
c.setFont('Helvetica-Bold', 18)
c.drawString(100,700, 'Hello World. This is page 1 of a 2 page document.')
c.showPage()
c.setFont('Helvetica-Bold', 16)
c.drawString(100,700, 'Page 2. This has some postscript drawing code.')
c.drawString(100,680, 'If you print it using a PS device and Acrobat 4/5,')
c.drawString(100,660, 'or export to Postscript, you should see the word')
c.drawString(100,640, '"Hello PostScript" below. In ordinary Acrobat Reader')
c.drawString(100,620, 'we expect to see nothing.')
c.addPostScriptCommand('/Helvetica findfont 48 scalefont setfont 100 400 moveto (Hello PostScript) show')
c.drawString(100,500, 'This document also inserts two postscript')
c.drawString(100,480, ' comments at beginning and endof the stream;')
c.drawString(100,460, 'search files for "%PS_BEFORE" and "%PS_AFTER".')
c.addPostScriptCommand('%PS_BEFORE', position=0)
c.addPostScriptCommand('%PS_AFTER', position=2)
c.save()
示例5: test0
def test0(self):
"This makes one long multi-page paragraph."
# Build story.
story = []
styleSheet = getSampleStyleSheet()
bt = styleSheet['BodyText']
text = '''If you imagine that the box of X's tothe left is
an image, what I want to be able to do is flow a
series of paragraphs around the image
so that once the bottom of the image is reached, then text will flow back to the
left margin. I know that it would be possible to something like this
using tables, but I can't see how to have a generic solution.
There are two examples of this in the demonstration section of the reportlab
site.
If you look at the "minimal" euro python conference brochure, at the end of the
timetable section (page 8), there are adverts for "AdSu" and "O'Reilly". I can
see how the AdSu one might be done generically, but the O'Reilly, unsure...
I guess I'm hoping that I've missed something, and that
it's actually easy to do using platypus.
'''
from reportlab.platypus.flowables import ParagraphAndImage, Image
from reportlab.lib.testutils import testsFolder
gif = os.path.join(testsFolder,'pythonpowered.gif')
story.append(ParagraphAndImage(Paragraph(text,bt),Image(gif)))
phrase = 'This should be a paragraph spanning at least three pages. '
description = ''.join([('%d: '%i)+phrase for i in xrange(250)])
story.append(ParagraphAndImage(Paragraph(description, bt),Image(gif),side='left'))
doc = MyDocTemplate(outputfile('test_platypus_paragraphandimage.pdf'))
doc.multiBuild(story)
示例6: test5
def test5(self):
from reportlab.lib.pagesizes import A4,LETTER
canv = canvas.Canvas(outputfile('test_pdfgen_general_page_sizes.pdf'),
pagesize=A4,
)
canv.setFont('Helvetica',10)
S = A4
canv.drawString(0,S[1]-10,'Top Left=(%s,%s) Page Size=%s x %s' % (0,S[1],S[0],S[1]))
canv.drawCentredString(0.5*S[0],0.5*S[1],'Center =(%s,%s) Page Size=%s x %s' % (0.5*S[0],0.5*S[1],S[0],S[1]))
canv.drawRightString(S[0],2,'Bottom Right=(%s,%s) Page Size=%s x %s' % (S[0],0,S[0],S[1]))
canv.showPage()
S = LETTER
canv.setPageSize(S)
canv.drawString(0,S[1]-10,'Top Left=(%s,%s) Page Size=%s x %s' % (0,S[1],S[0],S[1]))
canv.drawCentredString(0.5*S[0],0.5*S[1],'Center =(%s,%s) Page Size=%s x %s' % (0.5*S[0],0.5*S[1],S[0],S[1]))
canv.drawRightString(S[0],2,'Bottom Right=(%s,%s) Page Size=%s x %s' % (S[0],0,S[0],S[1]))
canv.showPage()
S = A4
canv.setPageSize(S)
canv.setPageRotation(180)
canv.drawString(0,S[1]-10,'Top Left=(%s,%s) Page Size=%s x %s' % (0,S[1],S[0],S[1]))
canv.drawCentredString(0.5*S[0],0.5*S[1],'Center =(%s,%s) Page Size=%s x %s' % (0.5*S[0],0.5*S[1],S[0],S[1]))
canv.drawRightString(S[0],2,'Bottom Right=(%s,%s) Page Size=%s x %s' % (S[0],0,S[0],S[1]))
canv.showPage()
S = A4[1],A4[0]
canv.setPageSize(S)
canv.setPageRotation(0)
canv.drawString(0,S[1]-30,'Top Left=(%s,%s) Page Size=%s x %s' % (0,S[1],S[0],S[1]))
canv.drawCentredString(0.5*S[0],0.5*S[1],'Center =(%s,%s) Page Size=%s x %s' % (0.5*S[0],0.5*S[1],S[0],S[1]))
canv.drawRightString(S[0],32,'Bottom Right=(%s,%s) Page Size=%s x %s' % (S[0],0,S[0],S[1]))
canv.showPage()
canv.save()
示例7: ___test2_all
def ___test2_all(self):
"""Dumps out ALl GLYPHS in a CID font.
Reach for your microscope :-)"""
try:
from reportlab.pdfbase.cidfonts import CIDFont, findCMapFile
findCMapFile('90ms-RKSJ-H')
findCMapFile('Identity-H')
except:
#don't have the font pack. return silently
return
pdfmetrics.registerFont(CIDFont('HeiseiMin-W3','Identity-H'))
c = Canvas('test_japanese_2.pdf')
c.setFont('Helvetica', 30)
c.drawString(100,800, 'All Glyphs in Adobe-Japan-1-2 collection!')
# the two typefaces
c.setFont('HeiseiMin-W3-Identity-H', 2)
x0 = 50
y0 = 700
dx = 2
dy = 2
for row in range(256):
for cell in range(256):
s = chr(row) + chr(cell)
x = x0 + cell*dx
y = y0 - row*dy
c.drawString(x,y,s)
c.save()
if VERBOSE:
print('saved '+outputfile('test_multibyte_jpn.pdf'))
示例8: test5
def test5(self):
from reportlab.lib.pagesizes import A4, LETTER
canv = canvas.Canvas(outputfile("test_pdfgen_general_page_sizes.pdf"), pagesize=A4)
canv.setFont("Helvetica", 10)
S = A4
canv.drawString(0, S[1] - 10, "Top Left=(%s,%s) Page Size=%s x %s" % (0, S[1], S[0], S[1]))
canv.drawCentredString(
0.5 * S[0], 0.5 * S[1], "Center =(%s,%s) Page Size=%s x %s" % (0.5 * S[0], 0.5 * S[1], S[0], S[1])
)
canv.drawRightString(S[0], 2, "Bottom Right=(%s,%s) Page Size=%s x %s" % (S[0], 0, S[0], S[1]))
canv.showPage()
S = LETTER
canv.setPageSize(S)
canv.drawString(0, S[1] - 10, "Top Left=(%s,%s) Page Size=%s x %s" % (0, S[1], S[0], S[1]))
canv.drawCentredString(
0.5 * S[0], 0.5 * S[1], "Center =(%s,%s) Page Size=%s x %s" % (0.5 * S[0], 0.5 * S[1], S[0], S[1])
)
canv.drawRightString(S[0], 2, "Bottom Right=(%s,%s) Page Size=%s x %s" % (S[0], 0, S[0], S[1]))
canv.showPage()
S = A4
canv.setPageSize(S)
canv.setPageRotation(180)
canv.drawString(0, S[1] - 10, "Top Left=(%s,%s) Page Size=%s x %s" % (0, S[1], S[0], S[1]))
canv.drawCentredString(
0.5 * S[0], 0.5 * S[1], "Center =(%s,%s) Page Size=%s x %s" % (0.5 * S[0], 0.5 * S[1], S[0], S[1])
)
canv.drawRightString(S[0], 2, "Bottom Right=(%s,%s) Page Size=%s x %s" % (S[0], 0, S[0], S[1]))
canv.showPage()
canv.save()
示例9: tearDown
def tearDown(self):
"Hook method for deconstructing the test fixture after testing it."
if FINISHED:
path=outputfile('test_graphics_charts.pdf')
doc = MyDocTemplate(path)
doc.build(self.story)
示例10: func
def func(val):
story = [
DocAssert(val,'this should fail'),
DocPara('repr(doc._nameSpace)',escape=True),
]
doc = SimpleDocTemplate(outputfile('test_doc_programming_asserts.pdf'))
doc.build(story)
示例11: textAccum2
def textAccum2():
doc = MyDocTemplate(outputfile("test_platypus_accum2.pdf"), pagesize=(8.5 * inch, 11 * inch), showBoundary=1)
story = []
story.append(Paragraph("A table with 500 rows", styleSheet["BodyText"]))
sty = [
("GRID", (0, 0), (-1, -1), 1, colors.green),
("BOX", (0, 0), (-1, -1), 2, colors.red),
("FONTNAME", (0, 0), (-1, -1), "Helvetica"),
("FONTSIZE", (0, 0), (-1, -1), 10),
]
def myCV(s, fontName="Helvetica", fontSize=10, maxWidth=72):
return "\n".join(simpleSplit(s, fontName, fontSize, maxWidth))
data = [
[
PA.onDrawStr(str(i + 1), i + 1),
myCV("xx " * (i % 10), maxWidth=100 - 12),
myCV("blah " * (i % 40), maxWidth=200 - 12),
]
for i in range(500)
]
t = LongTable(data, style=sty, colWidths=[50, 100, 200])
story.append(t)
doc.build(story)
示例12: testAAbsoluteAndRelativeFields
def testAAbsoluteAndRelativeFields(self):
# the old test1 in pdfform
c = canvas.Canvas(outputfile("test_pdfbase_pdfform_formtest.pdf"))
# first page
c.setFont("Courier", 10)
c.drawString(100, 500, "hello world")
pdfform.textFieldAbsolute(c, "fieldA", 100, 600, 100, 20, "default value")
pdfform.textFieldAbsolute(c, "fieldB", 100, 300, 100, 50, "another default value", multiline=1)
pdfform.selectFieldAbsolute(c, "fieldC", "France", ["Canada", "France", "China"], 100, 200, 100, 20)
c.rect(100, 600, 100, 20)
pdfform.buttonFieldAbsolute(c, "field2", "Yes", 100, 700, width=20, height=20)
c.rect(100, 700, 20, 20)
pdfform.buttonFieldAbsolute(c, "field3", "Off", 100, 800, width=20, height=20)
c.rect(100, 800, 20, 20)
# second page
c.showPage()
c.setFont("Helvetica", 7)
c.translate(50, 20)
c.drawString(100, 500, "hello world")
pdfform.textFieldRelative(c, "fieldA_1", 100, 600, 100, 20, "default value 2")
c.setStrokeColorRGB(1, 0, 0)
c.setFillColorRGB(0, 1, 0.5)
pdfform.textFieldRelative(c, "fieldB_1", 100, 300, 100, 50, "another default value 2", multiline=1)
pdfform.selectFieldRelative(c, "fieldC_1", "France 1", ["Canada 0", "France 1", "China 2"], 100, 200, 100, 20)
c.rect(100, 600, 100, 20)
pdfform.buttonFieldRelative(c, "field2_1", "Yes", 100, 700, width=20, height=20)
c.rect(100, 700, 20, 20)
pdfform.buttonFieldRelative(c, "field3_1", "Off", 100, 800, width=20, height=20)
c.rect(100, 800, 20, 20)
c.save()
示例13: test0
def test0(self):
"Make a PDFgen document with most graphics features"
self.pageCount = 0
makeDocument(outputfile('test_pdfgen_callback.pdf'), pageCallBack=self.callMe)
#no point saving it!
assert self.pageCount >= 7, 'page count not called!'
示例14: test1
def test1(self):
"""Ilpo Nyyss\xf6nen posted this broken test"""
normalStyle = ParagraphStyle(name="normal")
keepStyle = ParagraphStyle(name="keep", keepWithNext=True)
content = [Paragraph("line 1", keepStyle), Indenter(left=1 * cm), Paragraph("line 2", normalStyle)]
doc = SimpleDocTemplate(outputfile("test_platypus_breaking1.pdf"))
doc.build(content)
示例15: test0
def test0(self):
"A basic document drawing some strings"
# if they do not have the Japanese font files, go away quietly
from reportlab.pdfbase.cidfonts import UnicodeCIDFont, findCMapFile
pdfmetrics.registerFont(UnicodeCIDFont('STSong-Light'))
c = Canvas(outputfile('test_multibyte_chs.pdf'))
c.setFont('Helvetica', 30)
c.drawString(100,700, 'Simplified Chinese Font Support')
c.setFont('Helvetica', 10)
c.drawString(100,680, 'Short sample: "China - Zhang Ziyi" (famous actress)')
# the two typefaces
hBoxText('\u4e2d\u56fd - \u7ae0\u5b50\u6021',
c,
100,
660,
'STSong-Light',
)
c.setFont('Helvetica',10)
c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber())
c.showPage()
## # full kuten chart in EUC
## c.setFont('Helvetica', 18)
## c.drawString(72,750, 'Characters available in GB 2312-80, EUC encoding')
## y = 600
## enc = 'GB_EUC_H'
## for row in range(1, 95):
## KutenRowCodeChart(row, 'STSong-Light',enc).drawOn(c, 72, y)
## y = y - 125
## if y < 50:
## c.setFont('Helvetica',10)
## c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber())
## c.showPage()
## y = 700
##
c.save()
if VERBOSE:
print('saved '+outputfile('test_multibyte_chs.pdf'))