It is also inspiring to me, because I have had the same idea and been working on something like this on-and-off since early 2022, but the contrast between your project and the state of mine[1] is like a textbook example of how to ship vs how not to ship:
• Instead of using an existing parser like pdf.js as you do, I started writing my own parser from scratch, in the process learning Rust and its Nom library for parsing, its integration with Webassembly, etc.
• I wrote not just a straightforward parser, but a crazy one that that preserves all the details like whitespace etc (what a typical parser is supposed to ignore), so that I can test whether it round-trips successfully.
• After I got it working, I didn't stop at "works on almost all PDFs in practice" (the same as with PDF.js or any other PDF implementation) but actually chased down and investigated every single failure, checking whether they work in any other PDF application/library (Preview, Chrome, qpdf, Adobe Reader, etc), until I could prove to my satisfaction that it's not a fault in the parser. (This is still not complete…)
• When I returned to this project again after several months, instead of making further progress I spent time starting to document the code, making minor improvements and tweaks, etc.
So the end result is that my project basically does nothing still, while you have a working PDF debugger. :) This is the difference between a project that intends to actually produce something and one that ends up being mostly for learning/fun with the goal mostly forgotten… not that I have any regrets :)
[Meta: Something similar is true of this comment too, which I started two days ago but left as a draft… until I finally had a burst of energy and posted just now.]
Returning to your project, a couple of feature requests:
- Provide a shortcut to jump directly to the node for page N, for any user-provided page number N.
- (Where possible) Some annotation of the page content stream operators — the Tj, Td, etc.
(Do consider making it an open-source project, whatever the quality of the code…)
[1]: https://github.com/shreevatsa/pdf-explorer / https://shreevatsa.net/pdf-explorer/
Few things that I have in nice-to-do features list, but hard to implement without writing my own parser: - edit nodes (with XREF table update) - raw source editor - show actual position in source
For seeing the raw source, after using such things for a bit (e.g. the output HTML file generated by https://github.com/desgeeko/pdfsyntax which is very good), I'm starting to feel it's nice to look at the first few times / in some cases, but in the long run / for large PDFs, maybe it's not really so useful or worth it.
When I was trying to improve my resume I added some custom Javascript to the PDF using Adobe Reader and what I learned is even Adobe's product makes it painful. Basically the process was something like this:
1. You add a script that loads at certain sections in the document. Let's say this is the equivalent of document.load.
2. To do this there's a field to add the full script which must be typed up correctly beforehand. Only after its added do you know it works and every syntax error requires you to edit your previous script, delete the script you added, and hope your new version works.
3. There's really no interactive way to work with the scripts. Their 'debugger' has almost no features at all or hints of syntax errors. Even getting a script to run in it requires finding the right combination of key strokes in a 1000+ line document on PDF scripting.
The programming itself though is quite simple. It's just Javascript with a different DOM and security model. You can still do event-based programming and write powerful programs - all running inside a PDF. But it will only run in firefox (using PDF.js I think) and Adobe reader (for the JS support.) I just thought I'd tell you that writing these JS programs in PDFs (1) actually seems to have a lot of unrealized potential and (2) the tooling to do so is terrible. So with better JS support it would be useful.
Is there a way to view the stream content in ASCII/Unicode instead of Base64/Hex?
This has saved me clogging up my PC by installing the Java runtime and iText RUPS.
And, thank you!
1. Is the source available anywhere? I'm curious to see how it works.
2. Is there a way to connect the structure displayed here, to the rendered version in the PDF? To visually display the subcomponents?
It's a bit different if you are looking at a tagged PDF, where the tagging structure is in there, but if you want to look at that in detail you are probably better served with e.g. ngPDF (https://ngpdf.com/) which will show the tagging structure including the mapping to rendered elements.
It heavily relies on the core part of PDF.js: I've made a fork of the PDF.js project, removed everything not related to the core part, and added an export for low-level primitives [1].
Also, as inspiration, I used the pdf.js.utils [2] project, which almost does the same but in a different form.
I wouldn't worry about the quality of the code. You get better by seeing other people's work and seeing alternative solutions to the problems you had.
Also, as I mentioned in another comment, this could easily be built into a quick trouble-checking app for POD work. Posting it would also let people fork it to make more task-specific apps.
I spotted a typo, which led me to a bug. When I click on a "stream contents" node, the right panel says "It's a actual content" (instead of "an"), and there is some mouse handling issue that prevents me from selecting the text in the right panel.