gpt4 book ai didi

python - ReportLab断言错误: path must start with a moveto or rect

转载 作者:行者123 更新时间:2023-12-01 07:29:07 26 4
gpt4 key购买 nike

我使用 Python 3.6 和当前的 reportlab 和 svg2rlg 库(截至本文发布)尝试了此操作,并在标题中得到了错误。:

from reportlab.graphics import renderPDF
from svglib.svglib import svg2rlg

c = Canvas(path+'To Print.pdf')
img27 = svg2rlg(path_to_.svg')
wd27 = img27.width/inch
ht27 = img27.height/inch
renderPDF.draw(img27, c, x=x27, y=y27)

它通常工作得很好,但我不知道如何解决它。我尝试过搜索此错误,但无法在任何地方找到它。

这是完整的回溯:

File "/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
execfile(filename, namespace)

File "/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "/Users/Drive/Scripts/PDF.py", line 604, in <module>
renderPDF.draw(img27, c, x=x27, y=y27)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderPDF.py", line 29, in draw
R.draw(renderScaledDrawing(drawing), canvas, x, y, showBoundary=showBoundary)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 201, in draw
self.drawNode(drawing)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderPDF.py", line 54, in drawNode
self.drawNodeDispatcher(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 282, in drawNodeDispatcher
self.drawGroup(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 311, in drawGroup
self.drawNode(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderPDF.py", line 54, in drawNode
self.drawNodeDispatcher(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 282, in drawNodeDispatcher
self.drawGroup(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 311, in drawGroup
self.drawNode(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderPDF.py", line 54, in drawNode
self.drawNodeDispatcher(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 282, in drawNodeDispatcher
self.drawGroup(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 311, in drawGroup
self.drawNode(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderPDF.py", line 54, in drawNode
self.drawNodeDispatcher(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 282, in drawNodeDispatcher
self.drawGroup(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 311, in drawGroup
self.drawNode(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderPDF.py", line 54, in drawNode
self.drawNodeDispatcher(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 282, in drawNodeDispatcher
self.drawGroup(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 311, in drawGroup
self.drawNode(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderPDF.py", line 54, in drawNode
self.drawNodeDispatcher(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 282, in drawNodeDispatcher
self.drawGroup(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 311, in drawGroup
self.drawNode(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderPDF.py", line 54, in drawNode
self.drawNodeDispatcher(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderbase.py", line 278, in drawNodeDispatcher
self.drawPath(node)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/renderPDF.py", line 183, in drawPath
isClosed = _renderPath(path, drawFuncs, forceClose=fill and autoclose=='pdf')

File "/anaconda3/lib/python3.6/site-packages/svglib/svglib.py", line 1075, in patchedRenderPath
return original_renderPath(path, drawFuncs, **kwargs)

File "/anaconda3/lib/python3.6/site-packages/reportlab/graphics/shapes.py", line 996, in _renderPath
drawFuncs[op](*points[i:j])

File "/anaconda3/lib/python3.6/site-packages/reportlab/pdfgen/pathobject.py", line 127, in close
self._code_append('h')

File "/anaconda3/lib/python3.6/site-packages/reportlab/pdfgen/pathobject.py", line 36, in _init_code_append
assert c.endswith(' m') or c.endswith(' re'), 'path must start with a moveto or rect'

AssertionError: path must start with a moveto or rect

最佳答案

看来最后的断言过于热心了。

File "/anaconda3/lib/python3.6/site-packages/reportlab/pdfgen/pathobject.py", line 36, in _init_code_append
assert c.endswith(' m') or c.endswith(' re'), 'path must start with a moveto or rect'

此位置的 c 的实际值是“h”(由堆栈跟踪中上面的调用填写)。如果您只是注释掉断言,它就可以正常工作。

也请让 ReportLab 的好心人知道,以便他们将来可以修复。

关于python - ReportLab断言错误: path must start with a moveto or rect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57299121/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com