本文整理汇总了Python中reportlab.lib.utils.getBytesIO函数的典型用法代码示例。如果您正苦于以下问题:Python getBytesIO函数的具体用法?Python getBytesIO怎么用?Python getBytesIO使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getBytesIO函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testFontFileFailures
def testFontFileFailures(self):
"Tests TTFontFile constructor error checks"
self.assertRaises(TTFError, TTFontFile, "nonexistent file")
self.assertRaises(TTFError, TTFontFile, getBytesIO(b""))
self.assertRaises(TTFError, TTFontFile, getBytesIO(b"invalid signature"))
self.assertRaises(TTFError, TTFontFile, getBytesIO(b"OTTO - OpenType not supported yet"))
self.assertRaises(TTFError, TTFontFile, getBytesIO(b"\0\1\0\0"))
开发者ID:Distrotech,项目名称:reportlab,代码行数:7,代码来源:test_pdfbase_ttfonts.py
示例2: testFontFileChecksum
def testFontFileChecksum(self):
"Tests TTFontFile and TTF parsing code"
F = TTFOpenFile("Vera.ttf")[1].read()
TTFontFile(getBytesIO(F), validate=1) # should not fail
F1 = F[:12345] + b"\xFF" + F[12346:] # change one byte
self.assertRaises(TTFError, TTFontFile, getBytesIO(F1), validate=1)
F1 = F[:8] + b"\xFF" + F[9:] # change one byte
self.assertRaises(TTFError, TTFontFile, getBytesIO(F1), validate=1)
开发者ID:Distrotech,项目名称:reportlab,代码行数:8,代码来源:test_pdfbase_ttfonts.py
示例3: testFontMaker
def testFontMaker(self):
"Tests TTFontMaker class"
ttf = TTFontMaker()
ttf.add("ABCD", b"xyzzy")
ttf.add("QUUX", b"123")
ttf.add("head", b"12345678xxxx")
stm = ttf.makeStream()
ttf = TTFontParser(getBytesIO(stm), 0)
self.assertEquals(ttf.get_table("ABCD"), b"xyzzy")
self.assertEquals(ttf.get_table("QUUX"), b"123")
开发者ID:Distrotech,项目名称:reportlab,代码行数:10,代码来源:test_pdfbase_ttfonts.py
示例4: _AsciiHexEncode
def _AsciiHexEncode(input):
"""Encodes input using ASCII-Hex coding.
This is a verbose encoding used for binary data within
a PDF file. One byte binary becomes two bytes of ASCII.
Helper function used by images."""
if isUnicode(input):
input = input.encode('utf-8')
output = getBytesIO()
output.write(binascii.b2a_hex(input))
output.write(b'>')
return output.getvalue()
开发者ID:Aeium,项目名称:dotStudio,代码行数:12,代码来源:pdfutils.py
示例5: trySomeColors
def trySomeColors(C,enforceColorSpace=None):
from reportlab.lib.utils import getBytesIO
out=getBytesIO()
canv = canvas.Canvas(out,enforceColorSpace=enforceColorSpace)
canv.setFont('Helvetica',10)
x = 0
y = 0
w,h = canv._pagesize
for c in C:
if y+10>h:
y = 0
x += 10
canv.setFillColor(c)
canv.rect(x,y,10,10,fill=1,stroke=0)
y += 10
canv.showPage()
canv.save()
开发者ID:QGIS-Unibern,项目名称:MasterPlugin,代码行数:17,代码来源:test_pdfgen_general.py
示例6: drawToString
def drawToString(d,
showBoundary=rl_config.showBoundary,
dviPreview='',
title='Diagra EPS',
company='ReportLab',
dept='',
preview=0):
"Outputs the EPS to a string in memory"
f = getBytesIO()
drawToFile(d, f,
dviPreview=dviPreview,
title = title,
dept = dept,
company = company,
preview = preview,
showBoundary=showBoundary)
return f.getvalue()
开发者ID:AndyKovv,项目名称:hostel,代码行数:17,代码来源:renderPS_SEP.py
示例7: makeStream
def makeStream(self):
"Finishes the generation and returns the TTF file as a string"
stm = getBytesIO()
write = stm.write
numTables = len(self.tables)
searchRange = 1
entrySelector = 0
while searchRange * 2 <= numTables:
searchRange = searchRange * 2
entrySelector = entrySelector + 1
searchRange = searchRange * 16
rangeShift = numTables * 16 - searchRange
# Header
write(pack(">lHHHH", 0x00010000, numTables, searchRange,
entrySelector, rangeShift))
# Table directory
tables = list(self.tables.items())
tables.sort() # XXX is this the correct order?
offset = 12 + numTables * 16
for tag, data in tables:
if tag == 'head':
head_start = offset
checksum = calcChecksum(data)
if isUnicodeType(tag):
tag = tag.encode('utf-8')
write(tag)
write(pack(">LLL", checksum, offset, len(data)))
paddedLength = (len(data)+3)&~3
offset = offset + paddedLength
# Table data
for tag, data in tables:
data += b"\0\0\0"
write(data[:len(data)&~3])
checksum = calcChecksum(stm.getvalue())
checksum = add32(0xB1B0AFBA, -checksum)
stm.seek(head_start + 8)
write(pack('>L', checksum))
return stm.getvalue()
开发者ID:jeffery9,项目名称:reportlab,代码行数:44,代码来源:ttfonts.py
示例8: _preview
def _preview(d,preview):
'''create a device dependent preview image from drawing d'''
from reportlab.graphics import renderPM
if isinstance(preview,(int,float)):
assert preview>0, "negative scaling is forbidden"
g = d
d = Drawing(g.width*preview, g.height*preview)
g.transform = (preview,0,0,preview,0,0) #scale so it fits
d.add(g)
pilf = getBytesIO()
transparent = getattr(g,'preview_transparent',None) or rl_config.eps_preview_transparent
kwds = dict(fmt='TIFF')
if transparent:
configPIL = {}
bg = configPIL['transparent'] = toColor(transparent)
kwds['configPIL'] = configPIL
kwds['bg'] = bg.int_rgb()
renderPM.drawToFile(d,pilf,**kwds)
return pilf.getvalue()
开发者ID:AndyKovv,项目名称:hostel,代码行数:19,代码来源:renderPS_SEP.py
示例9: makeStream
def makeStream(self):
"Finishes the generation and returns the TTF file as a string"
stm = getBytesIO()
write = stm.write
tables = self.tables
numTables = len(tables)
searchRange = 1
entrySelector = 0
while searchRange * 2 <= numTables:
searchRange = searchRange * 2
entrySelector = entrySelector + 1
searchRange = searchRange * 16
rangeShift = numTables * 16 - searchRange
# Header
write(pack(">lHHHH", 0x00010000, numTables, searchRange,
entrySelector, rangeShift))
# Table directory
offset = 12 + numTables * 16
wStr = (lambda x:write(bytes(tag,'latin1'))) if isPy3 else write
tables_items = list(sorted(tables.items()))
for tag, data in tables_items:
if tag == 'head':
head_start = offset
checksum = calcChecksum(data)
wStr(tag)
write(pack(">LLL", checksum, offset, len(data)))
paddedLength = (len(data)+3)&~3
offset = offset + paddedLength
# Table data
for tag, data in tables_items:
data += b"\0\0\0"
write(data[:len(data)&~3])
checksum = calcChecksum(stm.getvalue())
checksum = add32(0xB1B0AFBA, -checksum)
stm.seek(head_start + 8)
write(pack('>L', checksum))
return stm.getvalue()
开发者ID:CometHale,项目名称:lphw,代码行数:43,代码来源:ttfonts.py
示例10: encryptPdfInMemory
def encryptPdfInMemory(inputPDF,
userPassword, ownerPassword=None,
canPrint=1, canModify=1, canCopy=1, canAnnotate=1,
strength=40):
"""accepts a PDF file 'as a byte array in memory'; return encrypted one.
This is a high level convenience and does not touch the hard disk in any way.
If you are encrypting the same file over and over again, it's better to use
pageCatcher and cache the results."""
try:
from rlextra.pageCatcher.pageCatcher import storeFormsInMemory, restoreFormsInMemory
except ImportError:
raise ImportError('''reportlab.lib.pdfencrypt.encryptPdfInMemory failed because rlextra cannot be imported.
See http://developer.reportlab.com''')
(bboxInfo, pickledForms) = storeFormsInMemory(inputPDF, all=1, BBoxes=1)
names = list(bboxInfo.keys())
firstPageSize = bboxInfo['PageForms0'][2:]
#now make a new PDF document
buf = getBytesIO()
canv = Canvas(buf, pagesize=firstPageSize)
# set a standard ID while debugging
if CLOBBERID:
canv._doc._ID = "[(xxxxxxxxxxxxxxxx)(xxxxxxxxxxxxxxxx)]"
encryptCanvas(canv,
userPassword, ownerPassword,
canPrint, canModify, canCopy, canAnnotate,
strength=strength)
formNames = restoreFormsInMemory(pickledForms, canv)
for formName in formNames:
#need to extract page size in future
canv.doForm(formName)
canv.showPage()
canv.save()
return buf.getvalue()
开发者ID:CometHale,项目名称:lphw,代码行数:40,代码来源:pdfencrypt.py
示例11: testSubsetting
def testSubsetting(self):
"Tests TTFontFile and TTF parsing code"
ttf = TTFontFile("Vera.ttf")
subset = ttf.makeSubset([0x41, 0x42])
subset = TTFontFile(getBytesIO(subset), 0)
for tag in ('cmap', 'head', 'hhea', 'hmtx', 'maxp', 'name', 'OS/2',
'post', 'cvt ', 'fpgm', 'glyf', 'loca', 'prep'):
self.assert_(subset.get_table(tag))
subset.seek_table('loca')
for n in range(4):
pos = subset.read_ushort() # this is actually offset / 2
self.failIf(pos % 2 != 0, "glyph %d at +%d should be long aligned" % (n, pos * 2))
self.assertEquals(subset.name, b"BitstreamVeraSans-Roman")
self.assertEquals(subset.flags, FF_SYMBOLIC)
self.assertEquals(subset.italicAngle, 0.0)
self.assertNear(subset.ascent,759.765625)
self.assertNear(subset.descent,-240.234375)
self.assertEquals(subset.capHeight, 759.765625)
self.assertNear(subset.bbox, [-183.10546875, -235.83984375, 1287.109375, 928.22265625])
self.assertEquals(subset.stemV, 87)
开发者ID:Distrotech,项目名称:reportlab,代码行数:22,代码来源:test_pdfbase_ttfonts.py
示例12: _showWidgetProperties
def _showWidgetProperties(self, widget):
"""Dump all properties of a widget."""
props = widget.getProperties()
keys = props.keys()
keys.sort()
lines = []
for key in keys:
value = props[key]
f = getBytesIO()
pprint.pprint(value, f)
value = f.getvalue()[:-1]
valueLines = value.split('\n')
for i in range(1, len(valueLines)):
valueLines[i] = ' '*(len(key)+3) + valueLines[i]
value = '\n'.join(valueLines)
lines.append('%s = %s' % (key, value))
text = '\n'.join(lines)
self.story.append(Paragraph("<i>Properties of Example Widget</i>", self.bt))
self.story.append(Paragraph("", self.bt))
self.story.append(Preformatted(text, self.code))
开发者ID:jeffery9,项目名称:reportlab,代码行数:24,代码来源:graphdocpy.py
示例13: drawToString
def drawToString(d, msg="", showBoundary=rl_config._unset_,autoSize=1):
"Returns a PDF as a string in memory, without touching the disk"
s = getBytesIO()
drawToFile(d, s, msg=msg, showBoundary=showBoundary,autoSize=autoSize)
return s.getvalue()
开发者ID:jeffery9,项目名称:reportlab,代码行数:5,代码来源:renderPDF.py
示例14: drawToString
def drawToString(d, showBoundary=rl_config.showBoundary):
"Returns a PS as a string in memory, without touching the disk"
s = getBytesIO()
drawToFile(d, s, showBoundary=showBoundary)
return s.getvalue()
开发者ID:CometHale,项目名称:lphw,代码行数:5,代码来源:renderPS.py
示例15: drawToString
def drawToString(d,fmt='GIF', dpi=72, bg=0xffffff, configPIL=None, showBoundary=rl_config._unset_):
s = getBytesIO()
drawToFile(d,s,fmt=fmt, dpi=dpi, bg=bg, configPIL=configPIL)
return s.getvalue()
开发者ID:luannguyen49,项目名称:OdooPortable,代码行数:4,代码来源:renderPM.py
示例16: saveToString
def saveToString(self,fmt='GIF'):
s = getBytesIO()
self.saveToFile(s,fmt=fmt)
return s.getvalue()
开发者ID:luannguyen49,项目名称:OdooPortable,代码行数:4,代码来源:renderPM.py
示例17: test10
def test10(self):
"test open and read of a simple relative file"
from reportlab.lib.utils import open_and_read, getBytesIO
b = getBytesIO(_rel_open_and_read('../docs/images/Edit_Prefs.gif'))
b = open_and_read(b)
开发者ID:FatihZor,项目名称:infernal-twin,代码行数:5,代码来源:test_lib_utils.py
示例18: _drawImageLevel1
def _drawImageLevel1(self, image, x1, y1, x2=None,y2=None):
# Postscript Level1 version available for fallback mode when Level2 doesn't work
"""drawImage(self,image,x1,y1,x2=None,y2=None) : If x2 and y2 are ommitted, they are
calculated from image size. (x1,y1) is upper left of image, (x2,y2) is lower right of
image in piddle coordinates."""
# For now let's start with 24 bit RGB images (following piddlePDF again)
component_depth = 8
myimage = image.convert('RGB')
imgwidth, imgheight = myimage.size
if not x2:
x2 = imgwidth + x1
if not y2:
y2 = y1 + imgheight
drawwidth = x2 - x1
drawheight = y2 - y1
#print 'Image size (%d, %d); Draw size (%d, %d)' % (imgwidth, imgheight, drawwidth, drawheight)
# now I need to tell postscript how big image is
# "image operators assume that they receive sample data from
# their data source in x-axis major index order. The coordinate
# of the lower-left corner of the first sample is (0,0), of the
# second (1,0) and so on" -PS2 ref manual p. 215
#
# The ImageMatrix maps unit squre of user space to boundary of the source image
#
# The CurrentTransformationMatrix (CTM) maps the unit square of
# user space to the rect...on the page that is to receive the
# image. A common ImageMatrix is [width 0 0 -height 0 height]
# (for a left to right, top to bottom image )
# first let's map the user coordinates start at offset x1,y1 on page
self.code.extend([
'gsave',
'%s %s translate' % (x1,-y1 - drawheight), # need to start are lower left of image
'%s %s scale' % (drawwidth,drawheight),
'/scanline %d 3 mul string def' % imgwidth # scanline by multiples of image width
])
# now push the dimensions and depth info onto the stack
# and push the ImageMatrix to map the source to the target rectangle (see above)
# finally specify source (PS2 pp. 225 ) and by exmample
self.code.extend([
'%s %s %s' % (imgwidth, imgheight, component_depth),
'[%s %s %s %s %s %s]' % (imgwidth, 0, 0, -imgheight, 0, imgheight),
'{ currentfile scanline readhexstring pop } false 3',
'colorimage '
])
# data source output--now we just need to deliver a hex encode
# series of lines of the right overall size can follow
# piddlePDF again
rawimage = myimage.tostring()
hex_encoded = self._AsciiHexEncode(rawimage)
# write in blocks of 78 chars per line
outstream = getBytesIO(hex_encoded)
dataline = outstream.read(78)
while dataline != "":
self.code_append(dataline)
dataline= outstream.read(78)
self.code_append('% end of image data') # for clarity
self.code_append('grestore') # return coordinates to normal
开发者ID:jeffery9,项目名称:reportlab,代码行数:65,代码来源:renderPS.py
示例19: _AsciiHexEncode
def _AsciiHexEncode(self, input): # also based on piddlePDF
"Helper function used by images"
output = getBytesIO()
for char in input:
output.write('%02x' % ord(char))
return output.getvalue()
开发者ID:jeffery9,项目名称:reportlab,代码行数:6,代码来源:renderPS.py
示例20: _drawImageLevel2
def _drawImageLevel2(self, image, x1,y1, x2=None,y2=None): # Postscript Level2 version
'''At present we're handling only PIL'''
### what sort of image are we to draw
if image.mode=='L' :
imBitsPerComponent = 8
imNumComponents = 1
myimage = image
elif image.mode == '1':
myimage = image.convert('L')
imNumComponents = 1
myimage = image
else :
myimage = image.convert('RGB')
imNumComponents = 3
imBitsPerComponent = 8
imwidth, imheight = myimage.size
if not x2:
x2 = imwidth + x1
if not y2:
y2 = y1 + imheight
drawwidth = x2 - x1
drawheight = y2 - y1
self.code.extend([
'gsave',
'%s %s translate' % (x1,-y1 - drawheight), # need to start are lower left of image
'%s %s scale' % (drawwidth,drawheight)])
if imNumComponents == 3 :
self.code_append('/DeviceRGB setcolorspace')
elif imNumComponents == 1 :
self.code_append('/DeviceGray setcolorspace')
# create the image dictionary
self.code_append("""
<<
/ImageType 1
/Width %d /Height %d %% dimensions of source image
/BitsPerComponent %d""" % (imwidth, imheight, imBitsPerComponent) )
if imNumComponents == 1:
self.code_append('/Decode [0 1]')
if imNumComponents == 3:
self.code_append('/Decode [0 1 0 1 0 1] %% decode color values normally')
self.code.extend([ '/ImageMatrix [%s 0 0 %s 0 %s]' % (imwidth, -imheight, imheight),
'/DataSource currentfile /ASCIIHexDecode filter',
'>> % End image dictionary',
'image'])
# after image operator just need to dump image dat to file as hexstring
rawimage = myimage.tostring()
hex_encoded = self._AsciiHexEncode(rawimage)
# write in blocks of 78 chars per line
outstream = getBytesIO(hex_encoded)
dataline = outstream.read(78)
while dataline != "":
self.code_append(dataline)
dataline= outstream.read(78)
self.code_append('> % end of image data') # > is EOD for hex encoded filterfor clarity
self.code_append('grestore') # return coordinates to normal
开发者ID:jeffery9,项目名称:reportlab,代码行数:61,代码来源:renderPS.py
注:本文中的reportlab.lib.utils.getBytesIO函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论