Viewing .pdf files

Javier Castrillo escribió:

Is there any way to view .pdf files into wxPython running on GNU /
Linux? I saw the pdfwindow in the demo but it only works in m$windows.

I appreciate your help

regards

Maybe you can integrate this project within wxGTK:

https://launchpad.net/poppler-python

Basically, it allows to call Poppler (the PDF rendering engine behind Evince, Okular, etc.) from Python. It even comes with an pyGTK demo app:

http://bazaar.launchpad.net/~poppler-python/poppler-python/trunk/annotate/head%3A/demo/demo-poppler.py

It seems to depend on a Cairo drawing context to do the rendering, not really in PyGTK (the library used in the example):

def __init__(self):
[...]
self.document = poppler.document_new_from_file (uri, None)
self.n_pages = self.document.get_n_pages()
self.current_page = self.document.get_page(0)
self.scale = 1
self.width, self.height = self.current_page.get_size()
[...]
self.dwg = gtk.DrawingArea()
self.dwg.set_size_request(int(self.width), int(self.height))
self.dwg.connect("expose-event", self.on_expose)

[...]
def on_expose(self, widget, event):
     cr = widget.window.cairo_create()
     cr.set_source_rgb(1, 1, 1)

     if self.scale != 1:
         cr.scale(self.scale, self.scale)

     cr.rectangle(0, 0, self.width, self.height)
     cr.fill()
     self.current_page.render(cr)

And you can use Cairo from wxPython:

http://wiki.wxpython.org/UsingCairoWithWxPython

So, (anyone else can give some more hints here) I think you can use python-poppler to render a PDF in a Cairo Drawing Context. I compiled it myself and it seems to works fine.

Just one more thing, python-poppler requires a recent version of libpoppler (>= 0.10), I had to compile it too (Ubuntu 8.10 comes with libpoppler 0.8.x), but the process was without hitches. :wink:

Ubuntu 9.04 (now in beta) has libpoppler 0.10.x.

If you have the time to test this, please answer in this thread. :slight_smile:

Regards, (Saludos!)
Marcelo

···

--
Marcelo F. Fernández
Buenos Aires, Argentina
Licenciado en Sistemas - CCNA

E-Mail: fernandezm22@yahoo.com.ar
Jabber ID: fernandezm22@jabber.org
Public Key ID: 5C990A6C 111C3661
Blog: http://marcelosoft.blogspot.com

Marcelo Fernández escribió:

Javier Castrillo escribió:

Is there any way to view .pdf files into wxPython running on GNU /
Linux? I saw the pdfwindow in the demo but it only works in m$windows.

I appreciate your help

regards

Maybe you can integrate this project within wxGTK:

Poppler Python Bindings in Launchpad

Basically, it allows to call Poppler (the PDF rendering engine behind Evince, Okular, etc.) from Python. It even comes with an pyGTK demo app:

~poppler-python/poppler-python/trunk : contents of demo/demo-poppler.py at revision 79

Well, I couldn't resist anymore and in 5 minutes got it working! :smiley:

Here is the source code:

I only merged the wxCairo example with the poppler-python demo (the "expose" window event), lines 81:88. From here, the sky is the limit! :slight_smile:

I attach a screenshot:
http://img129.imageshack.us/img129/5562/pantallazog.png

I hope it helps,
Marcelo

···

--
Marcelo F. Fernández
Buenos Aires, Argentina
Licenciado en Sistemas - CCNA

E-Mail: fernandezm22@yahoo.com.ar
Jabber ID: fernandezm22@jabber.org
Public Key ID: 5C990A6C 111C3661
Blog: http://marcelosoft.blogspot.com

Marcelo Fernández wrote:

Marcelo Fernández escribió:

Javier Castrillo escribió:

Is there any way to view .pdf files into wxPython running on GNU /
Linux? I saw the pdfwindow in the demo but it only works in m$windows.

I appreciate your help

regards

Maybe you can integrate this project within wxGTK:

Poppler Python Bindings in Launchpad

Basically, it allows to call Poppler (the PDF rendering engine behind Evince, Okular, etc.) from Python. It even comes with an pyGTK demo app:

~poppler-python/poppler-python/trunk : contents of demo/demo-poppler.py at revision 79

Well, I couldn't resist anymore and in 5 minutes got it working! :smiley:

Here is the source code:
Marcelo Fernndez - Pastebin.com

I only merged the wxCairo example with the poppler-python demo (the "expose" window event), lines 81:88. From here, the sky is the limit! :slight_smile:

I attach a screenshot:
ImageShack - Best place for all of your image hosting and image sharing needs

I hope it helps,
Marcelo

woah thanks for this, I'm using ImageMagick currently to render my PDFs which takes a long time, especially with larger PDFs so maybe something like this would be a better solution
Thanks a bunch, Marcelo!

Why not just use what the OS offers. Every OS offers some sort of viewer.
Linux has many
viewers = ("gpdf", "kpdf", "evince", "acroread", "xpdf", "firefox",
          "mozilla-firefox")

Then use os.system() to open.

for v in viewers:
  r = os.system("which %s 1> /dev/null 2> /dev/null" % v)
  if r == 0:
               do something

···

On Thursday 09 April 2009 08:48:31 pm Steven Sproat wrote:

Marcelo Fernández wrote:
> Marcelo Fernández escribió:
>> Javier Castrillo escribió:
>>> Is there any way to view .pdf files into wxPython running on GNU /
>>> Linux? I saw the pdfwindow in the demo but it only works in m$windows.
>>>
>>> I appreciate your help
>>>
>>> regards
>>
>> Maybe you can integrate this project within wxGTK:
>>
>> Poppler Python Bindings in Launchpad
>>
>> Basically, it allows to call Poppler (the PDF rendering engine behind
>> Evince, Okular, etc.) from Python. It even comes with an pyGTK demo app:
>>
>> http://bazaar.launchpad.net/~poppler-python/poppler-python/trunk/annotat
>>e/head%3A/demo/demo-poppler.py
>
> Well, I couldn't resist anymore and in 5 minutes got it working! :smiley:
>
> Here is the source code:
> Marcelo Fernndez - Pastebin.com
>
> I only merged the wxCairo example with the poppler-python demo (the
> "expose" window event), lines 81:88. From here, the sky is the limit! :slight_smile:
>
> I attach a screenshot:
> ImageShack - Best place for all of your image hosting and image sharing needs
>
> I hope it helps,
> Marcelo

woah thanks for this, I'm using ImageMagick currently to render my PDFs
which takes a long time, especially with larger PDFs so maybe something
like this would be a better solution
Thanks a bunch, Marcelo!

--
John Fabiani

johnf wrote:

···

On Thursday 09 April 2009 08:48:31 pm Steven Sproat wrote:
  

Marcelo Fernández wrote:
    

Marcelo Fernández escribió:
      

Javier Castrillo escribió:
        

Is there any way to view .pdf files into wxPython running on GNU /
Linux? I saw the pdfwindow in the demo but it only works in m$windows.

I appreciate your help

regards
          

Maybe you can integrate this project within wxGTK:

Poppler Python Bindings in Launchpad

Basically, it allows to call Poppler (the PDF rendering engine behind
Evince, Okular, etc.) from Python. It even comes with an pyGTK demo app:

http://bazaar.launchpad.net/~poppler-python/poppler-python/trunk/annotat
e/head%3A/demo/demo-poppler.py
        

Well, I couldn't resist anymore and in 5 minutes got it working! :smiley:

Here is the source code:
Marcelo Fernndez - Pastebin.com

I only merged the wxCairo example with the poppler-python demo (the
"expose" window event), lines 81:88. From here, the sky is the limit! :slight_smile:

I attach a screenshot:
ImageShack - Best place for all of your image hosting and image sharing needs

I hope it helps,
Marcelo
      

woah thanks for this, I'm using ImageMagick currently to render my PDFs
which takes a long time, especially with larger PDFs so maybe something
like this would be a better solution
Thanks a bunch, Marcelo!
    
Why not just use what the OS offers. Every OS offers some sort of viewer. Linux has many viewers = ("gpdf", "kpdf", "evince", "acroread", "xpdf", "firefox", "mozilla-firefox")

Then use os.system() to open.

for v in viewers:
  r = os.system("which %s 1> /dev/null 2> /dev/null" % v)
  if r == 0:
               do something

If the file type is associated with a program, you can probably use os.startfile(path)

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Marcelo Fernández wrote:

Marcelo Fernández escribió:

Javier Castrillo escribió:

Is there any way to view .pdf files into wxPython running on GNU /
Linux? I saw the pdfwindow in the demo but it only works in m$windows.

I appreciate your help

regards

Maybe you can integrate this project within wxGTK:

Poppler Python Bindings in Launchpad

Basically, it allows to call Poppler (the PDF rendering engine behind Evince, Okular, etc.) from Python. It even comes with an pyGTK demo app:

~poppler-python/poppler-python/trunk : contents of demo/demo-poppler.py at revision 79

Well, I couldn't resist anymore and in 5 minutes got it working! :smiley:

Here is the source code:
Marcelo Fernndez - Pastebin.com

I only merged the wxCairo example

Using the wx.lib.wxcairo module will save you a few steps, and will also work on all platforms.

with the poppler-python demo (the "expose" window event), lines 81:88. From here, the sky is the limit! :slight_smile:

Very cool. I had looked briefly at poppler before, but I didn't realize it was based on Cairo.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn escribió:

Marcelo Fernández wrote:

Here is the source code:
Marcelo Fernndez - Pastebin.com

I only merged the wxCairo example

Using the wx.lib.wxcairo module will save you a few steps, and will also work on all platforms.

Great, I quickly googled "wxpython cairo" and went to that wiki page
instead of the wx.lib.wxcairo api module... I'll take a look at it and
will try to make a simpler cross-platform example, to post it here.

The problem is that poppler seems to be distributed in source-code form, so one has to compile it first and poppler-python on top of it. But both seems to work fine in win32 and mac osx. The only dependency is cairo (for poppler) and pycairo [1][2] for poppler-python.

PyCairo web page:
[1] Pycairo

PyCairo Win32 binary:
[2] Index of /binaries/win32/pycairo/1.4/

Correct me if I'm wrong. But I think the big advantage here is to render PDFs natively in Linux, BSD, OSX and etc., not so in Windows (thanks to the ActiveX support).

Regards
Marcelo

···

--
Marcelo F. Fernández
Buenos Aires, Argentina
Licenciado en Sistemas - CCNA

E-Mail: fernandezm22@yahoo.com.ar
Jabber ID: fernandezm22@jabber.org
Public Key ID: 5C990A6C 111C3661
Blog: http://marcelosoft.blogspot.com

Marcelo Fernández escribió:

Robin Dunn escribió:

Marcelo Fernández wrote:

Here is the source code:
Marcelo Fernndez - Pastebin.com

I only merged the wxCairo example

Using the wx.lib.wxcairo module will save you a few steps, and will also work on all platforms.

Great, I quickly googled "wxpython cairo" and went to that wiki page
instead of the wx.lib.wxcairo api module... I'll take a look at it and
will try to make a simpler cross-platform example, to post it here.

Hi, just to add more info to the thread, using wx.lib.wxcairo, the source code gets *very* small:

I only noticed two things regarding dependencies:

- wx.lib.wxcairo is only available with wxWidgets/wxPython 2.8.9.0 onwards, which is included in very recent versions of Linux and Free OSes (for example, Ubuntu and Suse will have 2.8.9.x in the next version, and only Fedora 10 has it now).

- To make this example, I installed Ubuntu 9.04 Beta in a Virtual Machine, and I didn't have to compile poppler-python bindings, because it is included in the standard Ubuntu 9.04 repositories (it appears like "python-poppler" in the package manager). But neither Fedora and OpenSUSE seems to include it in the "development" repositories as of today.

Regards
Marcelo

···

--
Marcelo F. Fernández
Buenos Aires, Argentina
Licenciado en Sistemas - CCNA

E-Mail: fernandezm22@yahoo.com.ar
Jabber ID: fernandezm22@jabber.org
Public Key ID: 5C990A6C 111C3661
Blog: http://marcelosoft.blogspot.com