Start counting from actual beginning of PDF file

Fixes #4384.