Google Docs Viewer is no longer accessible at https://docs.google.com/viewer. (2015-10-11T00:59:08Z)

Google Docs Viewer helper for local documents (gdv.py) is a Python script which provides an easy way to use Google Docs Viewer to view documents on your hard-disks.


I am no longer using this method after I discovered PDF.js in Firefox and Ive switched to MuPDF since 2014-04-02. (2015-10-11T00:46:58Z)

gdv.py will start a HTTP server and open a new tab in web browser with a URL to Google Docs Viewer, which contains a link back to the HTTP server gdv.py just starts, so Google Docs Viewer can download the document file from that server.

2   Download the code

The Python code gdv.py (New BSD License) can be downloaded on GitHub.

3   Why I wrote this

Because xpdf gives me Segmentation fault which I dont know the cause after updates, and openmotif is only depended by xpdf. I had so wanted to unmerge openmotif, now I finally can.

After Segmentation fault occurred, I needed to view a PDF file, but I didnt have any other viewer installed. An immediate solution is using python -m SimpleHTTPServer and manually composed of a URL for Google Docs Viewer to access. If you have many documents you need to read, that would be very !#$%^&*.

Moreover, you have to start a server, go to Google Docs Viewers page, enter the URL, click the generation button, then click on the link to view. Too many steps!

I want the similar old way with xpdf: xpdf pdf_file. With gdv.py, I only run gdv.py doc_file. Simple and easy.

The best thing is it supports every file format which Google Docs Viewer supports.

4   Behind the scene

How this works?

  1. Getting an external IP using http://icanhazip.com/.
  2. Checking if port is opened.
  3. Starting HTTP server.
  4. Using webbrowser to open an URL, which is at Google Docs Viewer and contains a URL of HTTP server.
  5. Waiting for request to come in, of course, we hope thats from Google. Once a request in, server checks if the file name matches. If not, deny the request and exits.
  6. Once document file is sent, the program ends.

Note that the server only complete one request only. It will not stay, there is no need for serving forever.