0

I am trying to create an application that has a feature of displaying pdf files and decided to use wxpython to do this due to the pdfviewer class.

I made sure that I have pyPDF2 and pyPdf. (can use either but installed both to see if that was the issue.)

However when I run the code at the bottom. (taken from here) (got rid of the ``` on lines 31 and 17. Added wx before .VSCROLL and .SUNKEN_BORDER on line 16) I get the message:

Traceback (most recent call last):
  File "E:\Test\pdf.py", line 4, in <module>
    from wx.lib.pdfviewer import pdfViewer, pdfButtonPanel
  File "C:\Python34\lib\site-packages\wx\lib\pdfviewer\__init__.py", line 124, in <module>
    from viewer import pdfViewer
ImportError: No module named 'viewer'

When I then went to that package file to confirm that the module viewer was there I then ran it and line 124 worked. It just doesnt work when running through this example file which I assume is the same as when it will be in my application.

Does anyone know what I need to do to fix this. This module looks perfect for what I plan on doing.

Thanks

import wx
import wx.lib.sized_controls as sc

from wx.lib.pdfviewer import pdfViewer, pdfButtonPanel

class PDFViewer(sc.SizedFrame):
    def __init__(self, parent, **kwds):
        super(PDFViewer, self).__init__(parent, **kwds)

        paneCont = self.GetContentsPane()
        self.buttonpanel = pdfButtonPanel(paneCont, wx.NewId(),
                                wx.DefaultPosition, wx.DefaultSize, 0)
        self.buttonpanel.SetSizerProps(expand=True)
        self.viewer = pdfViewer(paneCont, wx.NewId(), wx.DefaultPosition,
                                wx.DefaultSize,
                                wx.HSCROLL|wx.VSCROLL|wx.SUNKEN_BORDER)
        self.viewer.UsePrintDirect = False
        self.viewer.SetSizerProps(expand=True, proportion=1)

        # introduce buttonpanel and viewer to each other
        self.buttonpanel.viewer = self.viewer
        self.viewer.buttonpanel = self.buttonpanel


if __name__ == '__main__':
    import wx.lib.mixins.inspection as WIT
    app = WIT.InspectableApp(redirect=False)


    pdfV = PDFViewer(None, size=(800, 600))
    pdfV.viewer.UsePrintDirect = False
    pdfV.viewer.LoadFile(r'a path to a .pdf file')
    pdfV.Show()

    app.MainLoop()
Rowan Knight
  • 451
  • 3
  • 14
  • Just found another post saying that the wx.lib widgets haven't been ported. But that was in 2013. http://stackoverflow.com/a/17278124 – Rowan Knight Apr 13 '15 at 11:59
  • Which version of wxPython are you using and what OS? – Mike Driscoll Apr 13 '15 at 14:38
  • Since you appear to be using Python3, please test if changing that line to `from .viewer import pdfViewer` fixes the import problem. – RobinDunn Apr 13 '15 at 16:19
  • @MikeDriscoll Windows 8.1 hoping to make the final thing cross platform though. Fixed it by downgrading to 2.7.9. (Also does your book ship to the UK?) – Rowan Knight Apr 14 '15 at 08:06
  • @RobinDunn It changes the error to: `SystemError: Parent module '' not loaded, cannot perform relative import` – Rowan Knight Apr 14 '15 at 08:10
  • @kni9ht there are other issues with pdfviewer on Py3, I started a PR https://github.com/RobinD42/Phoenix/pull/109 . This uses PyPDF2 but even with that there are issues in PyPDF2 on Py3.4 and pyPdf is no longer maintained, tried it but no look either. – Werner Apr 14 '15 at 10:22
  • @Werner Ok so that github is the start of a fix list? I noticed that the example given in python 2.7 only shows the layout of pdf documents that I have given it. (doesn't even recognise text there) – Rowan Knight Apr 14 '15 at 12:28
  • @kni9ht - I believe Lulu supports international sales. – Mike Driscoll Apr 14 '15 at 18:42
  • @kni9ht yes the PR on github is a start to fixing things. But the fix is not only in wxPython but also in PyPDF2. In Py2.7 it should show a PDF as it is shown in e.g. Acrobat reader, if that is not the case then there is possibly an issue with the PDF file itself or PyPDF2 does not handle it correctly. – Werner Apr 15 '15 at 13:38

1 Answers1

0

This needed a bit of work to get pdfviewer to work on Py3, I did a PR for it. Not the PR switches from pyPDF to PyPDF2 as the former does not support Py3 and it also depends on PR 172 someone has done to get PyPDF2 to work correctly on Py3.

Werner
  • 2,086
  • 1
  • 15
  • 14