Many times I create a PDF either programmatically and there might be a problem with it, e.g. some specific letter might no show up well or I might have encoding issues etc.
Is there some way to debug a PDF? E.g. see it's detailed structure?
Many times I create a PDF either programmatically and there might be a problem with it, e.g. some specific letter might no show up well or I might have encoding issues etc.
Is there some way to debug a PDF? E.g. see it's detailed structure?
There are a number of free tools that'll let you look at the guts of a PDF, uncompressed and decrypted (given the password).
RUPS for iText springs to mind (but I'm biased). I don't know that there's an iTextSharp equivalent. It's a GUI with a tree view (something ALL these apps have) of the PDF objects.
Some will let you edit the PDF within that tree, but not many. I believe Windjack's PDF CanOpener will (along with several other spiffy features you'd expect from a commercial Acrobat plugin).
And in a pinch, <insert favorite text editor here> works... but don't try to change anything. PDF is a binary format: byte offsets are important. If your text editor changes the \n to a \r\n (or tries to interpret it as UTF-8, or, or, or), your PDF will be Horribly Broken. Don't do that.
I end up doing a lot of searching for a given object number to look up indirect references. It's always a pain to look up a single digit reference because "4 obj" shows up at the end of every tenth object (14, 24, 34, 1234, etc). A regex search that looked for "beginning of line-4 obj-end of line" would be great, but I generally use notepad, so that's out (and I'm not much of a regex guy anyway).
PS: Even with a spiffy Acrobat plugin(not can opener, home grown from way back), I still need to crack open a text editor from time to time.
Acrobat will make changes at times as it loads a PDF (mostly to fix things), and if you want to know What's Really There, you need to look at that PDF in some other way. And when you're trying to debug a broken PDF, acrobat being helpful is the last thing you need.
PPS: Acrobat also has a spiffy "pdf syntax check" in its advanced->preflight profiles. It's also got checks for various PDF/* standards (PDF/X, PDF/A-1 [a and b], etc), accessibility, and so forth. They're invaluable when you're trying to Be Compliant. Not quite the debugging tool you were asking about, but Very Handy none the less.
PPPS: "diff"ing two PDFs is all but impossible, without writing a custom tool to do it for you. I wrote something that listed all the pages (with sizes) and fields (with types, flags, etc) in a predictable order and dumped it to a text file so I could diff the files... but directly diffing two PDFs is pointless. There are too many ways for "identical" files to differ (object order, dictionary key order, compression levels, etc).
java -jar itext-rups-5.5.9-jar-with-dependencies.jar
. –
Sciamachy Well, I wanted to debug some PDF files that I was generating using pdfLaTeX the other day, and I found that Adobe [Acrobat] Reader was not very helpful, as the slightly invalid PDFs I was producing would open as if there was no problem, they only failed to close. This made the TeX/View/Edit cycle a bit of a pain, since I would have to terminate the entire Reader process before I could TeX again.
I achieved more favorable results using Ghostscript. In my case, this was by way of GSview since I was using Windows; if I had been using Linux, I would have used gv instead. Not only did this not prevent me from re-TeXing the file (even while it was still open), it was nice enough to produce nigh-incomprehensible error messages rather than pretending everything was okay. These enabled me, with a bit of squinting, to see what I'd messed up in my PDF code and finally to produce the example given in this tex.SE answer of mine
It would have been nice if I could have figured out how to tell Ghostscript to include slightly more detail in the error message (well, I probably could have, if I'd looked at the right part of the manual for long enough, actually), but it wasn't that hard to figure out what I'd messed up by comparing the PDF with the Ghostscript error message and with Adobe's PDF reference. (I link to the archive page because the PDF references there were produced entirely by Adobe, and are of much higher typographic quality as well as much smaller size than the ISO standard for PDF that is on the main page.)
Of course, in order to make any sense of it in your text editor, it will probably be important that the page streams not be compressed, so I would suggest you figure out how to instruct your software not to compress them, or find something with which to uncompress them again afterwards.
So, in short:
Don't use Adobe [Acrobat] Reader (until you think your PDF is good, anyway).
Do try to instruct your software to refrain from compressing page streams.
Do use a text editor to look at the PDF (preferably set to "PostScript" mode, as the syntax is closely related).
Do use the PDF reference.
You can see the structure of a PDF using a tool like CanOpener, PDFedit or Acrobat (I wrote a blog article on the subject at http://www.jpedal.org/PDFblog/2010/09/useful-pdf-tools-pdfedit/)
This is what I usually do in Linux:
Install qpdf
package and run qpdf --qdf --object-streams=disable orig.pdf decoded.pdf
. Now you can open decoded.pdf
in a text editor and see the pdf source.
Also I installed PDFedit on linux which has a gui program which let you inspect all the pdf structure, from the comfort of a graphical interface. RUPS is a similar application, both of them are available in Flathub (so easy to install no matter your Linux distro):
https://flathub.org/apps/details/net.sourceforge.Pdfedit
https://flathub.org/apps/details/com.itextpdf.RUPS
How about http://blog.didierstevens.com/programs/pdf-tools/ or http://podofo.sourceforge.net/about.html
For a list of PDF tools and libraries - http://en.wikipedia.org/wiki/List_of_PDF_software You may find other tools there that fit your needs.
another tool would be pdfstreamdumper
https://github.com/dzzie/pdfstreamdumper
its actually quite intuitive to go through
made to analyze javascript / as3 code etc
has built in quite a few things
(hexviewer / refactor (deobfucators) etc)
You can also use PDFBox
jar to debug a pdf file:
java -jar pdfbox-app.*.jar PDFDebugger file.pdf
Just open it in some text editor. PDF is actually an ASCII file (and it can contain embedded binary data).
© 2022 - 2024 — McMap. All rights reserved.
name too long
(which in my case helped me narrow down the problem of the corruption on my latex ubuntu system). – Beachhead