New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZeroDivisionError: float division by zero #20
Comments
Had this same error and after quite a lot of reduction found the cause in the html. With a lot of crazy stuff in the html (<script>, <style>, @, doctype) it turns out that the bug was set off by one line of css in a style tag. I can't work out why this exact line of css was broken -- but it was definitely cause of this error: The error was resolved when the 'padding' style was removed: Regards! Note that I have the following line further up that did not cause this bug: |
Hi. I had this problem only when trying to render a table which contained a lot of rows. I confirm that the above solution worked for me. Thanks! |
I can confirm that the above error happens (in the case of a large table, combined with a "padding: 4px" css). Removing the line "works", i.e. makes it no longer crash (but costs us dearly in the layout). |
It seems to me the division by zero is caused by the variable Similarly, the value of
will trigger
|
I had the same issue, paading fixed it. But this is not a fix! |
I had the same issue but with empty html tags Fixed it with a non breaking space in every empty tag. Sorry I wanted to leave an example but the html disappears need a link to the comment docs. |
any updates on this issue? I have found that the culprit is the top and bottom padding, minimum usable value is 1px |
Another culprit...
|
Any news on this? No padding nor width with percentages yet I get this error with a lot of data, and it happens randomly (sometimes fails, sometimes ok) |
Hello, yes it is alive :) Can you maybe send me the files so I can try to recreate the error. didi@ribalba.de Cheers |
Looks like it is fixed on 0.0.6, at least for my case, but since there are many possible options causing it I can't tell exactly. |
Bring xhtml2pdf to the current 0.0.6 version. It is compatible with the project and it solves issues when generating reports with large amount of rows that caused "Division by zero" errors caused by the CSS even though the css was valid. See for reference on the error: xhtml2pdf/xhtml2pdf#20 I have had to revisit my css as the structure of the generation is slightly different, but not much work required.
Not seeing this issue anymore |
Hi,
I get this error while trying to parse an HTML containing the following piece of code.
I'm using the latest versions of all packages needed:
and Python 2.7 (2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)])
Python Code:
-[
import cStringIO as StringIO
from xhtml2pdf import pisa
....
html = '''
<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2">
<TR>
<TD></TD>
</TR>
</TABLE>
'''
dest = file('test.pdf', "wb")
pdf = pisa.CreatePDF(
StringIO.StringIO(html),
dest,
log_warn = 1,
log_err = 1
)
]-
Note: If I put something inside the TD (example: ".... <TD>... some stuff..... </TD>........") or I change the value of the attr cellpadding, it works!!!
Traceback:
-[
Traceback (most recent call last):
File "C:\tmp\test.py", line 95, in
log_err = 1
File "C:\Python27\lib\site-packages\xhtml2pdf\document.py", line 131, in pisaDocument
doc.build(context.story)
File "C:\Python27\lib\site-packages\reportlab\platypus\doctemplate.py", line 880, in build
self.handle_flowable(flowables)
File "C:\Python27\lib\site-packages\reportlab\platypus\doctemplate.py", line 763, in handle_flowable
if frame.add(f, canv, trySplit=self.allowSplitting):
File "C:\Python27\lib\site-packages\reportlab\platypus\frames.py", line 174, in _add
flowable.drawOn(canv, self._x + self._leftExtraIndent, y, _sW=aW-w)
File "C:\Python27\lib\site-packages\reportlab\platypus\flowables.py", line 108, in drawOn
self._drawOn(canvas)
File "C:\Python27\lib\site-packages\reportlab\platypus\flowables.py", line 89, in _drawOn
self.draw()#this is the bit you overload
File "C:\Python27\lib\site-packages\reportlab\platypus\tables.py", line 1302, in draw
self._drawCell(cellval, cellstyle, (colpos, rowpos), (colwidth, rowheight))
File "C:\Python27\lib\site-packages\reportlab\platypus\tables.py", line 1393, in _drawCell
w, h = self._listCellGeom(cellval,colwidth,cellstyle,W=W, H=H,aH=rowheight)
File "C:\Python27\lib\site-packages\xhtml2pdf\xhtml2pdf_reportlab.py", line 710, in _listCellGeom
return Table._listCellGeom(self, V, w, s, W=W, H=H, aH=aH)
File "C:\Python27\lib\site-packages\reportlab\platypus\tables.py", line 377, in _listCellGeom
vw, vh = v.wrapOn(canv, aW, aH)
File "C:\Python27\lib\site-packages\reportlab\platypus\flowables.py", line 119, in wrapOn
w, h = self.wrap(aW,aH)
File "C:\Python27\lib\site-packages\xhtml2pdf\xhtml2pdf_reportlab.py", line 693, in wrap
return KeepInFrame.wrap(self, availWidth, availHeight)
File "C:\Python27\lib\site-packages\reportlab\platypus\flowables.py", line 970, in wrap
W, H = func(s1)
File "C:\Python27\lib\site-packages\reportlab\platypus\flowables.py", line 951, in func
W /= x
ZeroDivisionError: float division by zero
]-
Thanks for your great job,
Shen139
The text was updated successfully, but these errors were encountered: