Added a console log. Seems to read the document length pixel fine. Somewhere in between it messes up