+# The ActiveX module from Acrobat 7.0 has changed and it seems to now
+# require much more from the container than what our wx.activex module
+# provides. If we try to use it via wx.activex then Acrobat crashes.
+# So instead we will use Internet Explorer (via the win32com modules
+# so we can use better dynamic dispatch) and embed the Acrobat control
+# within that. Acrobat provides the IAcroAXDocShim COM class that is
+# accessible via the IE window's Docuemnt property after a PDF file
+# has been loaded.
+
+if get_acroversion() >= '7.0':
+
+ from wx.lib.activexwrapper import MakeActiveXClass
+ import win32com.client.gencache
+ _browserModule = win32com.client.gencache.EnsureModule(
+ "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1)
+
+ class PDFWindowError(RuntimeError):
+ def __init__(self):
+ RuntimeError.__init__(self, "A PDF must be loaded before calling this method.")
+
+
+ class PDFWindow(wx.Panel):
+ def __init__(self, *args, **kw):
+ wx.Panel.__init__(self, *args, **kw)
+
+ # Make a new class that derives from the WebBrowser class
+ # in the COM module imported above. This class also
+ # derives from wxWindow and implements the machinery
+ # needed to integrate the two worlds.
+ _WebBrowserClass = MakeActiveXClass(_browserModule.WebBrowser)
+ self.ie = _WebBrowserClass(self, -1)
+ sizer = wx.BoxSizer()
+ sizer.Add(self.ie, 1, wx.EXPAND)
+ self.SetSizer(sizer)
+
+
+ def LoadFile(self, fileName):
+ if self.ie.Document:
+ return self.ie.Document.LoadFile(fileName)
+ else:
+ self.ie.Navigate2(fileName)
+ return True # can we sense failure at this point?
+
+ def GetVersions(self):
+ if self.ie.Document:
+ return self.ie.Document.GetVersions()
+ else:
+ raise PDFWindowError()
+
+ def Print(self):
+ if self.ie.Document:
+ return self.ie.Document.Print()
+ else:
+ raise PDFWindowError()
+
+ def goBackwardStack(self):
+ if self.ie.Document:
+ return self.ie.Document.goBackwardStack()
+ else:
+ raise PDFWindowError()
+
+ def goForwardStack(self):
+ if self.ie.Document:
+ return self.ie.Document.goForwardStack()
+ else:
+ raise PDFWindowError()
+
+ def gotoFirstPage(self):
+ if self.ie.Document:
+ return self.ie.Document.gotoFirstPage()
+ else:
+ raise PDFWindowError()
+
+ def gotoLastPage(self):
+ if self.ie.Document:
+ return self.ie.Document.gotoLastPage()
+ else:
+ raise PDFWindowError()
+
+ def gotoNextPage(self):
+ if self.ie.Document:
+ return self.ie.Document.gotoNextPage()
+ else:
+ raise PDFWindowError()
+
+ def gotoPreviousPage(self):
+ if self.ie.Document:
+ return self.ie.Document.gotoPreviousPage()
+ else:
+ raise PDFWindowError()
+
+ def printAll(self):
+ if self.ie.Document:
+ return self.ie.Document.printAll()
+ else:
+ raise PDFWindowError()
+
+ def printAllFit(self, shrinkToFit):
+ if self.ie.Document:
+ return self.ie.Document.printAllFit()
+ else:
+ raise PDFWindowError()
+
+ def printPages(self, from_, to):
+ if self.ie.Document:
+ return self.ie.Document.printPages()
+ else:
+ raise PDFWindowError()
+
+ def printPagesFit(self, from_, to, shrinkToFit):
+ if self.ie.Document:
+ return self.ie.Document.printPagesFit()
+ else:
+ raise PDFWindowError()
+
+ def printWithDialog(self):
+ if self.ie.Document:
+ return self.ie.Document.printWithDialog()
+ else:
+ raise PDFWindowError()
+
+ def setCurrentHighlight(self, a, b, c, d):
+ if self.ie.Document:
+ return self.ie.Document.setCurrentHighlight()
+ else:
+ raise PDFWindowError()
+
+ def setCurrentHightlight(self, a, b, c, d):
+ if self.ie.Document:
+ return self.ie.Document.setCurrentHightlight()
+ else:
+ raise PDFWindowError()
+
+ def setCurrentPage(self, n):
+ if self.ie.Document:
+ return self.ie.Document.setCurrentPage()
+ else:
+ raise PDFWindowError()
+
+ def setLayoutMode(self, layoutMode):
+ if self.ie.Document:
+ return self.ie.Document.setLayoutMode()
+ else:
+ raise PDFWindowError()
+
+ def setNamedDest(self, namedDest):
+ if self.ie.Document:
+ return self.ie.Document.setNamedDest()
+ else:
+ raise PDFWindowError()
+
+ def setPageMode(self, pageMode):
+ if self.ie.Document:
+ return self.ie.Document.setPageMode()
+ else:
+ raise PDFWindowError()
+
+ def setShowScrollbars(self, On):
+ if self.ie.Document:
+ return self.ie.Document.setShowScrollbars()
+ else:
+ raise PDFWindowError()
+
+ def setShowToolbar(self, On):
+ if self.ie.Document:
+ return self.ie.Document.setShowToolbar()
+ else:
+ raise PDFWindowError()
+
+ def setView(self, viewMode):
+ if self.ie.Document:
+ return self.ie.Document.setView()
+ else:
+ raise PDFWindowError()
+
+ def setViewRect(self, left, top, width, height):
+ if self.ie.Document:
+ return self.ie.Document.setViewRect()
+ else:
+ raise PDFWindowError()
+
+ def setViewScroll(self, viewMode, offset):
+ if self.ie.Document:
+ return self.ie.Document.setViewScroll()
+ else:
+ raise PDFWindowError()
+
+ def setZoom(self, percent):
+ if self.ie.Document:
+ return self.ie.Document.setZoom()
+ else:
+ raise PDFWindowError()
+
+ def setZoomScroll(self, percent, left, top):
+ if self.ie.Document:
+ return self.ie.Document.setZoomScroll()
+ else:
+ raise PDFWindowError()