For PDF files, see https://stackoverflow.com/questions/3549541/best-tool-for-inspecting-pdf-files

One of them is iText RUPS.

See also http://kaitai.io/ — not sure whether it includes a visualizer.

I’m trying to write something similar for DVI files (because no one else will).