Hi,
I know pdfviewer doesn’t support every pdf file, however, I was wondering if you could help with this one.
I have a simple application (python 2.7), which uses Report Lab to generate some reports.
In order to display these files, I was trying out the latest versions of wxWidgets and wxPython from github.
My system is running Ubuntu 13.04 x64 and everything compiled fine after a couple tries.
Next I ran the sample usage from pdfviewer docs to view the file attached.
Don’t know if this is relevant to my main question, but I got these errors:
Traceback (most recent call last):
File “repos/wxWidgets/Phoenix/wx/lib/pdfviewer/viewer.py”, line 161, in OnIdle
self.Render()
File “repos/wxWidgets/Phoenix/wx/lib/pdfviewer/viewer.py”, line 391, in Render
gc = GraphicsContext.Create(self.pdc) # Cairo/wx.GraphicsContext API
File “repos/wxWidgets/Phoenix/wx/lib/graphics.py”, line 1007, in Create
ctx = wx.lib.wxcairo.ContextFromDC(dc)
File “repos/wxWidgets/Phoenix/wx/lib/wxcairo.py”, line 122, in ContextFromDC
drawable = voidp( dc.GetHandle() )
File “repos/wxWidgets/Phoenix/wx/lib/wxcairo.py”, line 77, in voidp
return ctypes.c_void_p(long(ptr))
TypeError: long() argument must be a string or a number, not ‘sip.voidptr’
So I changed line 77 from wxcairo.py:
- return ctypes.c_void_p(long(ptr))
- return ctypes.c_void_p(long(ptr.int()))
And it started working.
However, the table in the file is not drawn, although the text is drawn just fine (as seen on the screenshot attached).
Am I doing something wrong, or does pdfviewer not support such tables?
Thanks,
Luis
file.pdf (2.02 KB)
Hi again,
I think I figured out the problem.
StrokePath on lib/graphics.py uses a wx.Pen object to draw, which expects width as an int.
However the width of the lines on my pdf are set to 0.25, which are truncated to 0 when cast to int.
Pdfviewer is not taking this into account and assumes line widths are floats. As such, any line with width < 1 is not drawn! I ended up changing lineWidth to get a minimum of 1, so that every line is at least drawn.
Should this be a bug on wxWidgets Pen?
Regards,
Luis
···
On Thursday, August 22, 2013 3:20:51 PM UTC+1, Luís Carvalho wrote:
Hi,
I know pdfviewer doesn’t support every pdf file, however, I was wondering if you could help with this one.
I have a simple application (python 2.7), which uses Report Lab to generate some reports.
In order to display these files, I was trying out the latest versions of wxWidgets and wxPython from github.
My system is running Ubuntu 13.04 x64 and everything compiled fine after a couple tries.
Next I ran the sample usage from pdfviewer docs to view the file attached.
Don’t know if this is relevant to my main question, but I got these errors:
Traceback (most recent call last):
File “repos/wxWidgets/Phoenix/wx/lib/pdfviewer/viewer.py”, line 161, in OnIdle
self.Render()
File “repos/wxWidgets/Phoenix/wx/lib/pdfviewer/viewer.py”, line 391, in Render
gc = GraphicsContext.Create(self.pdc) # Cairo/wx.GraphicsContext API
File “repos/wxWidgets/Phoenix/wx/lib/graphics.py”, line 1007, in Create
ctx = wx.lib.wxcairo.ContextFromDC(dc)
File “repos/wxWidgets/Phoenix/wx/lib/wxcairo.py”, line 122, in ContextFromDC
drawable = voidp( dc.GetHandle() )
File “repos/wxWidgets/Phoenix/wx/lib/wxcairo.py”, line 77, in voidp
return ctypes.c_void_p(long(ptr))
TypeError: long() argument must be a string or a number, not ‘sip.voidptr’
So I changed line 77 from wxcairo.py:
- return ctypes.c_void_p(long(ptr))
- return ctypes.c_void_p(long(ptr.int()))
And it started working.
However, the table in the file is not drawn, although the text is drawn just fine (as seen on the screenshot attached).
Am I doing something wrong, or does pdfviewer not support such tables?
Thanks,
Luis
Well, not a bug, but a serious limitation. wx.DC uses integer widths
-- so to get around that in wxPostscriptDC, it scales everything by a
factor of 100 ( or some value). Perhaps you could play that game in
your code.
There has been a feature request for floating point pen widths in
wxGraphicsContext for ages, though I don't know that anyone has gotten
around to doing it.
CHB
···
On Aug 23, 2013, at 3:37 AM, "Luís Carvalho" <mail.lmcarvalho@gmail.com> wrote:
StrokePath on lib/graphics.py uses a wx.Pen object to draw, which expects width as an int.
Should this be a bug on wxWidgets Pen?
I 'll see if I can modify PDFViewer to round up any line widths < 1 automatically
···
On Friday, August 23, 2013 11:37:27 AM UTC+1, Luís Carvalho wrote:
Hi again,
I think I figured out the problem.
StrokePath on lib/graphics.py uses a wx.Pen object to draw, which expects width as an int.
However the width of the lines on my pdf are set to 0.25, which are truncated to 0 when cast to int.
Pdfviewer is not taking this into account and assumes line widths are floats. As such, any line with width < 1 is not drawn! I ended up changing lineWidth to get a minimum of 1, so that every line is at least drawn.
–
Regards
David Hughes
Forestfield Software
OK, thanks.
I monkey-patched that by changing line #580 of viewer.py to
g.lineWidth = max(float(operand[0]), 1.0)
It does the job, unless the line width should be 0!
I don’t need the pdfviewer to be an exact replica of the pdf itself, so rounding it up to 1 is fine for me.
Regards,
Luis
···
On Friday, August 23, 2013 4:15:03 PM UTC+1, David Hughes wrote:
On Friday, August 23, 2013 11:37:27 AM UTC+1, Luís Carvalho wrote:
Hi again,
I think I figured out the problem.
StrokePath on lib/graphics.py uses a wx.Pen object to draw, which expects width as an int.
However the width of the lines on my pdf are set to 0.25, which are truncated to 0 when cast to int.
Pdfviewer is not taking this into account and assumes line widths are floats. As such, any line with width < 1 is not drawn! I ended up changing lineWidth to get a minimum of 1, so that every line is at least drawn.
I 'll see if I can modify PDFViewer to round up any line widths < 1 automatically
–
Regards
David Hughes
Forestfield Software