Thanks,
JamesNC++! I really appreciate you taking the time to post that. You clearly have a lot of experience with PDFs. My condolences.
Unfortunately your script is reporting R:0 for every PDF I try it on, even though some are clearly rotated. Perhaps I'm missing something. FWIW, these particular PDFs all have exactly one page (they came from various pdftk burst operations.)
Is there a particular reason why you are only buffering 256 bytes? I increased the buffer size to 65536 as it was taking several minutes to run on some of my PDFs.