Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you view the JavaScript embedded in a PDF?

Tags:

javascript

pdf

I have a PDF, which I think has JavaScript embedded in it. Is it possible to see what that JavaScript is? And if so, how would I see it?

It's probably possible to hack something together with iText, but I would prefer something faster.

like image 444
user833970 Avatar asked Mar 29 '13 15:03

user833970


1 Answers

If you prefer a fast method, just open the PDF with a text editor, e.g. NotePad++, and search on JavaScript.

In my case, I ran into a pdf that insisted on being printed instead of viewed. With NP++ I found this script:

<</S/JavaScript/JS(this.print\({bUI: true,bSilent: false,bShrinkToFit: true}\);this.closeDoc\(\);)>>

The notation is a little weird, but obviously it has a Print command, followed by a Close command.

You can even replace the Close command with spaces, which is easy in Overwrite mode (press the Insert key to toggle to and from Overwrite mode). You need to keep the total nr of characters the same, to preserve the offset pointers in the PDF. Then, the document can be viewed after cancelling the print command.

As it was a digitally signed document, of course the signature showed "invalid" :-)

like image 142
Roland Avatar answered Oct 13 '22 10:10

Roland