Python: PdfFileReader PdfReadError: EOF marker not found

I had this error when I was trying to read the content of a PDF file using python lib pyPDF.


it turns out to be that the PDF file I was trying to read is not a standard PDF file.

Standard PDF ends with “%%EOF” marker within the last 1024 bytes of the file.

But in order to see the content of a PDF, it does not have to be a standard one. So for this “broken” PDF, I could still view it correctly using most PDF reader but throws this EOF marker not found exception when I am using pyPDF library.

The solution it to change the pyPDF/ files:

def read(self, stream):
    # start at the end:, 2)
    line = ''
    while not line:
        line = self.readNextEndLine(stream)
    if line[:5] != "%%EOF":
        raise utils.PdfReadError, "EOF marker not found"


def read(self, stream):
    # start at the end:, 2)
    line = ''
    while line[:5] != "%%EOF":
        line = self.readNextEndLine(stream)

Javascript Base64 Encoding Decoding

I am having this painful thing because I was using Google’s GMail API.

I was trying to retrieve the body of the Email which turns out to be Base64 data.

The very first approach I could find is to use atob() function.

This works for some of the cases.

But not all of them.

When I decode using this atob() function, I sometimes see this error.

Uncaught InvalidCharacterError: Failed to execute ‘atob’ on ‘Window': The string to be decoded is not correctly encoded.

Test data is:


You can try this.  I do know this is valid base64 data because I could decode this correctly using python.

import base64


After searching quite a lot, I found this which works great for me.

I also heard that in Google Closure Library, goog.crypt.base64 is also a great one for encoding and decoding stuff. Cause I haven’t found out how to quick use this in my js, so I didn’t try this out.

Error: wiredep:app running grunt serve after yoeman generates angular project

yoeman is a scaffolding tool helpful for developers.

$ yo angular

creates an angular folder for you.

But it surprises me that after doing this, when I run

$ grunt serve

To start the localhost server, it gives me back error.

Running “wiredep:app” (wiredep) task
Warning: ENOENT, no such file or directory ‘/Users/txzhang/git/mm-motohire/app/bower.json’ Use –force to continue.

Aborted due to warnings.

To fix this, change the file Gruntfile.js in the root folder of your project.

wiredep: {
options: {
cwd: '<%= %>'
app: {
src: ['<%= %>/index.html'],
ignorePath: /\.\.\//

remove the line cwd:'<%= %>.

Then you would be good to go.

How to use custom font in web HTML

Sometimes you might want to use your own custom font for your web application.

Here is the quick way to do this.

Important: Make sure the file font-file.ttf stays in the same folder where the css file stays. I haven’t tried with relative position of the font-file in argument for url(). Maybe it would work.

In css file, you define the font-familiy

@font-face { font-family: font-name; src: url('font-file.ttf'); } 


     font-familiy: font-name;      


So then in your html, you could see your words in custom font

<p id="element_id">The words to show</p>

Build Angular Google App Engine Cloud Endpoints Application Notes Python

1 Build angular folders

Use Yeoman to help build Angular layout folder structure.

Running yo angular and select what library is needed for the probject.

2 Create app.yaml in the root folder of the project.

application: application-name
version: 0-1
runtime: python27
api_version: 1
threadsafe: true

- ^(.*/)?.*node_modules/.*$

# Endpoints handler
- url: /_ah/spi/.*
secure: always
- url: /bower_components
static_dir: bower_components

- url: (.*)/
static_files: app\1/index.html
upload: app
login: required
secure: always

- url: (.*)
static_files: app\1
upload: app
login: required
secure: always

- name: endpoints
version: "1.0"

Google App Engine: PDF reportlab Import Error ImportError: Cannot re-init internal module __main__

When using python library reportlab in appengine, I have met this import error.

 File "/Users/bmh/GitRepos/MyProject/charges/", line 15, in <module>
    from MyProject.invoices import generate_invoice, format_long_number
  File "/Users/bmh/GitRepos/MyProject/charges/", line 23, in <module>
    from reportlab.lib import colors
  File "/Users/bmh/GitRepos/MyProject/contrib/reportlab/lib/", line 44, in <module>
    from reportlab.lib.rl_accel import fp_str
  File "/Users/bmh/GitRepos/MyProject/contrib/reportlab/lib/", line 19, in <module>
    import __main__
ImportError: Cannot re-init internal module __main__

This import error will show up if you are running a old version of reportlab in appengine.

This is the issue people have submitted about this import error and it’s already fixed.

See this change.

So in order to make everything works, just go to the bitbucket repository and download the latest code(Version 3.1.10 or above should be fine).