Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8084893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:56:03+00:00 2026-06-05T17:56:03+00:00

This is a followup from here . I am trying to reload a pdf

  • 0

This is a followup from here. I am trying to reload a pdf file. Basically I want to watch the pdf file and as it changes, reload it in the viewer. I could not find any documentation for python+gtk3 and evince.

#!/usr/bin/env python

from gi.repository import Gtk, Gdk
from gi.repository import EvinceDocument
from gi.repository import EvinceView
import os,sys

if (len(sys.argv) is not 2):
    print "Usage: "+sys.argv[0]+" file.ext"
    sys.exit(0)
else:
    docFile=os.path.abspath(sys.argv[1])

#==========================================================
# Evince viewer class
class EvinceViewer:

    #------------------------------------------------------
    # constructor to build GUI and hook up function
    def __init__(self):

        # create main window
        self.window = Gtk.Window()
        # set title, size, position
        self.window.set_title("Evince")
        self.window.set_default_size(800,600)
        # connect destroy and delete events to quit
        self.window.connect('destroy', Gtk.main_quit)
        self.window.connect('delete-event', 
                Gtk.main_quit)
        self.window.connect("key-press-event", 
                self.keypress)

        # scrolled window for the viewer
        scroll = Gtk.ScrolledWindow()
        self.window.add(scroll)

        # evince document
        EvinceDocument.init()
        doc = EvinceDocument.Document.factory_get_document(
                'file://'+docFile)
        # evince view
        self.view = EvinceView.View()
        # evince model
        self.model = EvinceView.DocumentModel()
        self.model.set_document(doc)
        self.view.set_model(self.model)

        # add to scroll window
        scroll.add(self.view)
        self.window.show_all()
        self.fullscreen=False

    #------------------------------------------------------
    # handling keyboard events
    def keypress(self,widget,event):
        keyname = Gdk.keyval_name(event.keyval)
        ctrl = event.state & \
                Gdk.ModifierType.CONTROL_MASK

        if ctrl:

            if keyname=='r':
                self.view.reload()

            elif keyname == 'Return':
                if self.fullscreen == False:
                    self.fullscreen=True
                    self.window.fullscreen()
                else:
                    self.fullscreen=False
                    self.window.unfullscreen()

            elif keyname=='q':
                Gtk.main_quit()

    def main(self):
        Gtk.main()

if __name__ == "__main__":
    evinceViewer = EvinceViewer()
    evinceViewer.main()

The reload function does not seem to do the job. What is going wrong? On calling it, the document viewer displays a messed up version of the pdf file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:56:04+00:00Added an answer on June 5, 2026 at 5:56 pm

    According to http://git.gnome.org/browse/evince/tree/libview/ev-view.c, ev_view_reload and ev_view_reload_page only redraw the page; they don’t complete re-read the document. In your case, if you change the file without letting the library know, it’ll assume that the file hasn’t changed and attempt to render the document using reference tables from memory, causing it to behave erratically. If you change the document, you are going to have to reload the document itself.

    To do this (lines 63-64):

    if keyname=='r':
        self.model.get_document().load('file://'+docFile) # <- ADD THIS LINE
        self.view.reload()
    

    This will actually cause the library to completely reread the contents of the PDF file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a followup from another post at here . Problem: The code below
This is a followup from another post at here . Problem: links aren't been
This is a followup from Populating DropDownList inside Repeater not working . I'm adding
This is a followup to this question. Here's the code I'm trying to understand
This is a followup to a question I posted a few days ago. basically,
This is a followup question to my other question : Run bat file in
All, this is a follow up from a previous question here: C# formatting external
This Question arises from a Q&A here I have some doubts that i think
This is a followup question from this one. Connecting Pyside with matplotlib My PythonFu
This is a follow-up from my question here: How to record sequential collections of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.