本文整理汇总了Python中xhtml2pdf.context.pisaContext函数的典型用法代码示例。如果您正苦于以下问题:Python pisaContext函数的具体用法?Python pisaContext怎么用?Python pisaContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pisaContext函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_add_cell_styles_will_not_add_linebefore_style_if_borderleft_width_not_set_on_context_frag
def test_add_cell_styles_will_not_add_linebefore_style_if_borderleft_width_not_set_on_context_frag(self):
context = pisaContext([])
context.frag.borderLeftStyle = "solid"
context.frag.borderLeftWidth = "3px"
instance = self.sut()
instance.add_cell_styles(context, (0, 1), (3, 5), mode="tr")
self.assertNotEqual(instance.styles[0][0], 'LINEBEFORE')
开发者ID:Krukov,项目名称:xhtml2pdf,代码行数:7,代码来源:test_tables.py
示例2: test_add_cell_styles_will_not_add_linebelow_style_if_borderbottom_color_not_set_on_context_frag
def test_add_cell_styles_will_not_add_linebelow_style_if_borderbottom_color_not_set_on_context_frag(self):
context = pisaContext([])
context.frag.borderBottomStyle = "solid"
context.frag.borderBottomWidth = "3px"
instance = self.sut()
instance.add_cell_styles(context, (0, 1), (3, 5), mode="tr")
self.assertNotEqual(instance.styles[0][0], 'LINEBELOW')
开发者ID:Krukov,项目名称:xhtml2pdf,代码行数:7,代码来源:test_tables.py
示例3: test_add_cell_styles_will_not_add_lineabove_style_if_bordertop_style_not_set_on_context_frag
def test_add_cell_styles_will_not_add_lineabove_style_if_bordertop_style_not_set_on_context_frag(self):
context = pisaContext([])
context.frag.borderTopWidth = "3px"
context.frag.borderTopColor = "black"
instance = self.sut()
instance.add_cell_styles(context, (0, 1), (3, 5), mode="tr")
self.assertNotEqual(instance.styles[0][0], 'LINEABOVE')
开发者ID:Krukov,项目名称:xhtml2pdf,代码行数:7,代码来源:test_tables.py
示例4: pisaStory
def pisaStory(src, path=None, link_callback=None, debug=0, default_css=None,
xhtml=False, encoding=None, context=None, xml_output=None,
**kw):
# Prepare Context
if not context:
context = pisaContext(path, debug=debug)
context.pathCallback = link_callback
# Use a default set of CSS definitions to get an expected output
if default_css is None:
default_css = DEFAULT_CSS
# Parse and fill the story
pisaParser(src, context, default_css, xhtml, encoding, xml_output)
# Avoid empty documents
if not context.story:
context.story = [Spacer(1,1)]
if context.indexing_story:
context.story.append(context.indexing_story)
# Remove anchors if they do not exist (because of a bug in Reportlab)
for frag, anchor in context.anchorFrag:
if anchor not in context.anchorName:
frag.link = None
return context
开发者ID:AndrewJHart,项目名称:xhtml2pdf,代码行数:28,代码来源:document.py
示例5: test_add_cell_styles_will_not_add_lineafter_style_if_borderright_color_not_set_on_context_frag
def test_add_cell_styles_will_not_add_lineafter_style_if_borderright_color_not_set_on_context_frag(self):
context = pisaContext([])
context.frag.borderRightStyle = "solid"
context.frag.borderRightWidth = "3px"
instance = self.sut()
instance.add_cell_styles(context, (0, 1), (3, 5), mode="tr")
self.assertNotEqual(instance.styles[0][0], 'LINEAFTER')
开发者ID:Krukov,项目名称:xhtml2pdf,代码行数:7,代码来源:test_tables.py
示例6: test_height_as_list
def test_height_as_list(self):
"""Asserts attributes like 'height: 10px !important" are parsed"""
c = pisaContext(".")
data = b"<p style='height: 10px !important;width: 10px !important'>test</p>"
r = pisaParser(data, c)
self.assertEqual(c, r)
self.assertEqual(r.err, 0)
self.assertEqual(r.warn, 0)
开发者ID:Krukov,项目名称:xhtml2pdf,代码行数:8,代码来源:test_parser.py
示例7: test_add_cell_styles_will_add_linebelow_style_if_borderbottom_attrs_set_on_context_frag
def test_add_cell_styles_will_add_linebelow_style_if_borderbottom_attrs_set_on_context_frag(self):
context = pisaContext([])
context.frag.borderBottomStyle = "solid"
context.frag.borderBottomWidth = "3px"
context.frag.borderBottomColor = "black"
instance = self.sut()
instance.add_cell_styles(context, (0, 1), (3, 5), mode="tr")
self.assertEqual(instance.styles[0], ('LINEBELOW', (0, 5), (3, 5), '3px', 'black', 'squared'))
开发者ID:Krukov,项目名称:xhtml2pdf,代码行数:8,代码来源:test_tables.py
示例8: test_add_cell_styles_will_add_lineafter_style_if_borderright_attrs_set_on_context_frag
def test_add_cell_styles_will_add_lineafter_style_if_borderright_attrs_set_on_context_frag(self):
context = pisaContext([])
context.frag.borderRightStyle = "solid"
context.frag.borderRightWidth = "3px"
context.frag.borderRightColor = "black"
instance = self.sut()
instance.add_cell_styles(context, (0, 1), (3, 5), mode="tr")
self.assertEqual(instance.styles[0], ('LINEAFTER', (3, 1), (3, 5), '3px', 'black', 'squared'))
开发者ID:Krukov,项目名称:xhtml2pdf,代码行数:8,代码来源:test_tables.py
示例9: test_image_os_path
def test_image_os_path(self):
c = pisaContext(".")
tests_folder = os.path.dirname(os.path.realpath(__file__))
img_path = os.path.join(tests_folder, 'samples', 'img', 'denker.png')
data = '<img src="{0}">'.format(img_path).encode('utf-8')
r = pisaParser(data, c)
self.assertEqual(c, r)
self.assertEqual(r.err, 0)
self.assertEqual(r.warn, 0)
开发者ID:Krukov,项目名称:xhtml2pdf,代码行数:9,代码来源:test_parser.py
示例10: test_add_cell_styles_will_add_padding_styles_based_on_frag_padding_attrs
def test_add_cell_styles_will_add_padding_styles_based_on_frag_padding_attrs(self):
context = pisaContext([])
context.frag.paddingRight = 5
instance = self.sut()
instance.add_cell_styles(context, (0, 1), (3, 5), mode="td")
self.assertEqual(instance.styles[0], ('LEFTPADDING', (0, 1), (3, 5), 0))
self.assertEqual(instance.styles[1], ('RIGHTPADDING', (0, 1), (3, 5), 5))
self.assertEqual(instance.styles[2], ('TOPPADDING', (0, 1), (3, 5), 0))
self.assertEqual(instance.styles[3], ('BOTTOMPADDING', (0, 1), (3, 5), 0))
开发者ID:Krukov,项目名称:xhtml2pdf,代码行数:9,代码来源:test_tables.py
示例11: test_start_will_add_borders_if_border_and_border_color_set_in_attrs
def test_start_will_add_borders_if_border_and_border_color_set_in_attrs(self):
self.attrs.border = 2
self.attrs.bordercolor = "green"
tag = tables.pisaTagTABLE(self.element, self.attrs)
context = pisaContext([])
tag.start(context)
self.assertEqual(context.frag.borderLeftWidth, 2)
self.assertEqual(context.frag.borderRightWidth, 2)
self.assertEqual(context.frag.borderTopWidth, 2)
self.assertEqual(context.frag.borderBottomWidth, 2)
self.assertEqual(context.frag.borderLeftColor, "green")
self.assertEqual(context.frag.borderRightColor, "green")
self.assertEqual(context.frag.borderTopColor, "green")
self.assertEqual(context.frag.borderBottomColor, "green")
self.assertEqual(context.frag.borderLeftStyle, "solid")
self.assertEqual(context.frag.borderRightStyle, "solid")
self.assertEqual(context.frag.borderTopStyle, "solid")
self.assertEqual(context.frag.borderBottomStyle, "solid")
开发者ID:Krukov,项目名称:xhtml2pdf,代码行数:18,代码来源:test_tables.py
示例12: parseHTML
def parseHTML(data, node):
path = None
link_callback = None
debug = 0
default_css = HTML_CSS
xhtml = False
encoding = None
xml_output = None
capacity = 100 * 1024
# Prepare simple context
context = pisaContext(path, debug=debug, capacity=capacity)
context.pathCallback = link_callback
# Build story
context = pisaStory(
data, path, link_callback, debug, default_css, xhtml, encoding, context=context, xml_output=xml_output
)
return context.story
开发者ID:fjouret,项目名称:rst2pdf-py3-dev,代码行数:19,代码来源:utils.py
示例13: test_will_set_attrs_on_tabledata
def test_will_set_attrs_on_tabledata(self):
self.attrs.cellpadding = 4
self.attrs.align = "left"
self.attrs.repeat = True
self.attrs.width = 100
tag = tables.pisaTagTABLE(self.element, self.attrs)
context = pisaContext([])
tag.start(context)
self.assertEqual(context.tableData.padding, 4)
self.assertEqual(context.tableData.styles[0], ('LEFTPADDING', (0, 0), (-1, -1), 4))
self.assertEqual(context.tableData.styles[1], ('RIGHTPADDING', (0, 0), (-1, -1), 4))
self.assertEqual(context.tableData.styles[2], ('TOPPADDING', (0, 0), (-1, -1), 4))
self.assertEqual(context.tableData.styles[3], ('BOTTOMPADDING', (0, 0), (-1, -1), 4))
self.assertEqual(context.tableData.align, "LEFT")
self.assertEqual(context.tableData.col, 0)
self.assertEqual(context.tableData.row, 0)
self.assertEqual(context.tableData.colw, [])
self.assertEqual(context.tableData.rowh, [])
self.assertEqual(context.tableData.repeat, True)
self.assertEqual(context.tableData.width, 100.0)
开发者ID:Krukov,项目名称:xhtml2pdf,代码行数:20,代码来源:test_tables.py
示例14: test_add_cell_styles_will_add_all_line_styles_if_all_border_attrs_set_on_context_frag
def test_add_cell_styles_will_add_all_line_styles_if_all_border_attrs_set_on_context_frag(self):
context = pisaContext([])
context.frag.borderTopStyle = "solid"
context.frag.borderTopWidth = "3px"
context.frag.borderTopColor = "black"
context.frag.borderLeftStyle = "solid"
context.frag.borderLeftWidth = "3px"
context.frag.borderLeftColor = "black"
context.frag.borderRightStyle = "solid"
context.frag.borderRightWidth = "3px"
context.frag.borderRightColor = "black"
context.frag.borderBottomStyle = "solid"
context.frag.borderBottomWidth = "3px"
context.frag.borderBottomColor = "black"
instance = self.sut()
instance.add_cell_styles(context, (0, 1), (3, 5), mode="tr")
self.assertEqual(instance.styles[0], ('LINEABOVE', (0, 1), (3, 1), '3px', 'black', 'squared'))
self.assertEqual(instance.styles[1], ('LINEBEFORE', (0, 1), (0, 5), '3px', 'black', 'squared'))
self.assertEqual(instance.styles[2], ('LINEAFTER', (3, 1), (3, 5), '3px', 'black', 'squared'))
self.assertEqual(instance.styles[3], ('LINEBELOW', (0, 5), (3, 5), '3px', 'black', 'squared'))
开发者ID:Krukov,项目名称:xhtml2pdf,代码行数:20,代码来源:test_tables.py
示例15: pisaStory
def pisaStory(
src,
path = None,
link_callback = None,
debug = 0,
default_css = None,
xhtml = False,
encoding = None,
c = None,
xml_output = None,
**kw):
# Prepare Context
if not c:
c = pisaContext(path, debug=debug)
c.pathCallback = link_callback
# Use a default set of CSS definitions to get an expected output
if default_css is None:
default_css = DEFAULT_CSS
# Parse and fill the story
pisaParser(src, c, default_css, xhtml, encoding, xml_output)
#if 0:
# import reportlab.pdfbase.pdfmetrics as pm
# pm.dumpFontData()
# Avoid empty documents
if not c.story:
c.story = [Spacer(1,1)]
# c.addPara(force=True)
# Remove anchors if they do not exist (because of a bug in Reportlab)
for frag, anchor in c.anchorFrag:
if anchor not in c.anchorName:
frag.link = None
return c
开发者ID:stefanfoulis,项目名称:xhtml2pdf,代码行数:39,代码来源:document.py
示例16: test_getFile
def test_getFile(self):
c = pisaContext(".")
r = pisaParser(_data, c)
self.assertEqual(c.getFile(None), None)
开发者ID:wpj-cz,项目名称:xhtml2pdf,代码行数:4,代码来源:test_parser.py
示例17: testParser
def testParser(self):
c = pisaContext(".")
r = pisaParser(_data, c)
self.assertEqual(c, r)
开发者ID:wpj-cz,项目名称:xhtml2pdf,代码行数:4,代码来源:test_parser.py
示例18: pisaDocument
def pisaDocument(src, dest=None, path=None, link_callback=None, debug=0,
default_css=None, xhtml=False, encoding=None, xml_output=None,
raise_exception=True, capacity=100*1024, **kw):
log.debug("pisaDocument options:\n src = %r\n dest = %r\n path = %r\n link_callback = %r\n xhtml = %r",
src,
dest,
path,
link_callback,
xhtml)
# Prepare simple context
context = pisaContext(path, debug=debug, capacity=capacity)
context.pathCallback = link_callback
# Build story
context = pisaStory(src, path, link_callback, debug, default_css, xhtml,
encoding, context=context, xml_output=xml_output)
# Buffer PDF into memory
out = pisaTempFile(capacity=context.capacity)
doc = PmlBaseDoc(
out,
pagesize=context.pageSize,
author=context.meta["author"].strip(),
subject=context.meta["subject"].strip(),
keywords=[x.strip() for x in
context.meta["keywords"].strip().split(",") if x],
title=context.meta["title"].strip(),
showBoundary=0,
allowSplitting=1)
# Prepare templates and their frames
if "body" in context.templateList:
body = context.templateList["body"]
del context.templateList["body"]
else:
x, y, w, h = getBox("1cm 1cm -1cm -1cm", context.pageSize)
body = PmlPageTemplate(
id="body",
frames=[
Frame(x, y, w, h,
id="body",
leftPadding=0,
rightPadding=0,
bottomPadding=0,
topPadding=0)],
pagesize = context.pageSize)
doc.addPageTemplates([body] + context.templateList.values())
# Use multibuild e.g. if a TOC has to be created
if context.multiBuild:
doc.multiBuild(context.story)
else:
doc.build(context.story)
# Add watermarks
if pyPdf:
for bgouter in context.pisaBackgroundList:
# If we have at least one background, then lets do it
if bgouter:
istream = out
output = pyPdf.PdfFileWriter()
input1 = pyPdf.PdfFileReader(istream)
ctr = 0
# TODO: Why do we loop over the same list again?
# see bgouter at line 137
for bg in context.pisaBackgroundList:
page = input1.getPage(ctr)
if (bg and not bg.notFound()
and (bg.mimetype=="application/pdf")):
bginput = pyPdf.PdfFileReader(bg.getFile())
pagebg = bginput.getPage(0)
pagebg.mergePage(page)
page = pagebg
else:
log.warn(context.warning(
"Background PDF %s doesn't exist.", bg))
output.addPage(page)
ctr += 1
out = pisaTempFile(capacity=context.capacity)
output.write(out)
# data = sout.getvalue()
# Found a background? So leave loop after first occurence
break
else:
log.warn(context.warning("pyPDF not installed!"))
# Get the resulting PDF and write it to the file object
# passed from the caller
if dest is None:
# No output file was passed - Let's use a pisaTempFile
dest = pisaTempFile(capacity=context.capacity)
context.dest = dest
data = out.getvalue() # TODO: That load all the tempfile in RAM - Why bother with a swapping tempfile then?
#.........这里部分代码省略.........
开发者ID:AndrewJHart,项目名称:xhtml2pdf,代码行数:101,代码来源:document.py
示例19: test_image_base64
def test_image_base64(self):
c = pisaContext(".")
data = b'<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=">'
r = pisaParser(data, c)
self.assertEqual(r.warn, 0)
开发者ID:Krukov,项目名称:xhtml2pdf,代码行数:5,代码来源:test_parser.py
示例20: pisaDocument
def pisaDocument(
src,
dest = None,
path = None,
link_callback = None,
debug = 0,
show_error_as_pdf = False,
default_css = None,
xhtml = False,
encoding = None,
xml_output = None,
raise_exception = True,
capacity = 100 * 1024, # -1,
**kw):
c = None
if show_error_as_pdf:
raise_exception = False
try:
log.debug("pisaDocument options:\n src = %r\n dest = %r\n path = %r\n link_callback = %r\n xhtml = %r",
src,
dest,
path,
link_callback,
xhtml)
# Prepare simple context
c = pisaContext(path, debug=debug, capacity=capacity)
c.pathCallback = link_callback
if dest is None:
dest = pisaTempFile(capacity=c.capacity)
c.dest = dest
# Build story
c = pisaStory(src, path, link_callback, debug, default_css, xhtml, encoding, c=c, xml_output=xml_output)
# Buffer PDF into memory
out = pisaTempFile(capacity=c.capacity)
doc = PmlBaseDoc(
out,
pagesize = c.pageSize,
author = c.meta["author"].strip(),
subject = c.meta["subject"].strip(),
keywords = [x.strip() for x in c.meta["keywords"].strip().split(",") if x],
title = c.meta["title"].strip(),
showBoundary = 0,
allowSplitting = 1)
# XXX It is not possible to access PDF info, because it is private in canvas
# doc.info.producer = "pisa <http://www.holtwick.it>"
# Prepare templates and their frames
if c.templateList.has_key("body"):
body = c.templateList["body"]
del c.templateList["body"]
else:
x, y, w, h = getBox("1cm 1cm -1cm -1cm", c.pageSize)
body = PmlPageTemplate(
id="body",
frames=[
Frame(x, y, w, h,
id = "body",
leftPadding = 0,
rightPadding = 0,
bottomPadding = 0,
topPadding = 0)],
pagesize = c.pageSize)
# print body.frames
# print [body] + c.templateList.values()
doc.addPageTemplates([body] + c.templateList.values())
doc._pisa_page_counter = 0
def _page_counter(page_no):
doc._pisa_page_counter += 1
doc.setPageCallBack(_page_counter)
# Use multibuild e.g. if a TOC has to be created
if c.multiBuild:
doc.multiBuild(c.story)
else:
doc.build(c.story)
c._pisa_page_counter = doc._pisa_page_counter
# Add watermarks
if pyPdf:
for bgouter in c.pisaBackgroundList:
# If we have at least one background, then lets do it
if bgouter:
istream = out
try:
output = pyPdf.PdfFileWriter()
#.........这里部分代码省略.........
开发者ID:stefanfoulis,项目名称:xhtml2pdf,代码行数:101,代码来源:document.py
注:本文中的xhtml2pdf.context.pisaContext函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论