#9 Zoom function in PDF Preview



Here is a proposal for an improvement on the great patch "PDF Preview in SplitView - ID: 2799221" by Dan Mihai Ile.

The differences with and additions to the above mentioned patch are:
- the ability to zoom in or out in the pdf preview, with the aid of two buttons in the toolbar
- the preview width and zoom factor are automatically saved in the preferences
- when resizing the window, the preview keeps the same size, and the editor is resized (it was the contrary before)
- the handling of the initial width of the preview uses now the "set_size_request" method (no need for the "gobject.timeout_add(10, self.adjust_width)")
- the document is initially shown centered horizontally, even if it is larger than the preview panel
- when the document is zoomed in or out, the top of the current view stays at the top after the zoom
- when the preview panel is resized, the (horizontal) center of the current view remains at the center, instead of keeping the left border at the same place
- the border of each page is drawn without antialiasing, so that it looks sharper
- a shadow is drawn under each page

The reason for all these horizontal centerings is that on small screens, users may not want to display the whole width of the pages, but only the part where there is text, hiding thus the margins. The above features aim at simplifying this procedure.

The buttons used to zoom in and out should ideally be hidden when the preview is not active, but I don't know how to do this (probably not because it's difficult, but only because I'm ignorant).

I also tried to add accelerators for these buttons (naively copying what is done for menu items), but I did not succeed.

And finally it would be nice if there could be accelerators to scroll the preview without using the mouse (which is, I think, the only way to do it now), but here again, I don't know how to do it.

The attached patches are against revision 340 in svn. Place them in the src subdirectory, and type

patch base/config.py base_config.py.patch
patch latex/actions.py latex_actions.py.patch
patch latex/editor.py latex_editor.py.patch
patch latex/livepreview.py latex_livepreview.py.patch

(not really the svn way, sorry)

Best regards,



  • Yannick Voglaire

    Hi again,

    I have made some small improvements, which I attach now. There are now accelerators and menu items to move in the preview only with the keyboard (these are still not hidden when the preview is toggled off, though). Moreover, internally, all references to the preview panel are released each time it is recreated or toggled off (callback functions are properly disconnected), so that the preview panel is really destroyed.
    I also corrected some mistakes, related to the scale, in the creation of the border of each page (wasn't really 1 pixel) and the horizontal centering which should be correct now.

    I've been trying to add support for postscript preview as well. This requires wrapping the C libspectre library (it is used by evince, so should be present in any Gnome distribution) in python. I tried using ctypes, it turned out to work more or less but to be extremely slow and memory consuming (one of the difficulties was in converting python arrays to writable C arrays to be passed by reference to the rendering function). So my view on this now is that (unless someone with more experience with ctypes can help on this) it will be easier and more efficient to do what was done for libpoppler: write a glib interface to libspectre, and then write a python module in C, binding to the glib interface (this should to be done anyway at some point, as rendering postscript documents in python is something that may be useful). Fortunately, libspectre has a lot less functions that poppler, due to the absence of attachments, references, forms, actions, and so on. I'll be trying to do that from now on, but as I haven't much time, it won't be too soon.

    Best regards,


  • Michael Zeising

    Michael Zeising - 2009-10-04

    Thanks a lot! I'll have a look as soon as I have the time ;)


  • Michael Zeising

    Michael Zeising - 2009-10-04
    • priority: 5 --> 7
  • Michael Zeising

    Michael Zeising - 2009-11-17
    • status: open --> closed-accepted
  • Michael Zeising

    Michael Zeising - 2009-11-17

    Thanks a lot for your work! I've just applied your patch in SVN... two questions:

    - what is the <Super> key in shortcuts? Is it mac specific?
    - would you like to join the developers team and commit changes to the preview code directly?



Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks