Track code in a PDF or PostScript file

Is there a way to track the opening of a PDF file? Perhaps by embedding some script in the PDF file itself?

I saw the question below and I believe the answer is no for javascript, but I wonder if this is possible at all.

Paste the Google Analytics tracking code into a PDF file

+4
pdf postscript pdf-generation tracking
source share
4 answers

The PDF standard includes support for JavaScript, but as @Wes Hardaker noted, not every PDF reader supports it. However, sometimes some are better than no one.

Here's the official Adobe Scripting Guide for Acrobat JavaScript . Probably the most interesting for you is the doc object, which has a method called getURL() . To use it, you simply call:

 app.doc.getURL('http://www.google.com/'); 

Bind this event to an open document and you have a tracker. I'm not too good at creating events from Adobe Acrobat, but from code is pretty easy. The code below is a complete working application VS2010 C # WinForms using the open source library iTextSharp (5.1.1.0). It creates a PDF file and adds JavaScript to an open event.

Some notes . Adobe Acrobat and Reader will alert the user whenever a document accesses an external resource. Most other PDF readers are likely to do the same. This is very annoying, so for this reason it should not be done. Personally, I don’t care if someone is following my document, I just don’t want to get hints every time. Secondly, to repeat this code, this code works for Adobe Acrobat and Adobe Reader, perhaps at least in V6, but it may or may not work in other PDF readers. Thirdly, there is no reliable way to uniquely identify a user. To do this, you need to create and save some equivalent cookie, which will require you to write to the user's file system, which will be considered unsafe. This means that you can only detect the number of discoveries, not a unique discovery. Fourthly, this may not be legal everywhere. Some jurisdictions require you to notify users that you are tracking them and to allow them to see what information you collect.

But with all of the above, I can’t give an answer just because I don’t like it.

 using System; using System.Text; using System.Windows.Forms; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //File that we will create string OutputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Events.pdf"); //Standard PDF creation setup using (FileStream fs = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None)) { using (Document doc = new Document(PageSize.LETTER)) { using (PdfWriter writer = PdfWriter.GetInstance(doc, fs)) { //Open our document for writing doc.Open(); //Create an action that points to the built-in app.doc object and calls the getURL method on it PdfAction act = PdfAction.JavaScript("app.doc.getURL('http://www.google.com/');", writer); //Set that action as the documents open action writer.SetOpenAction(act); //We need to add some content to this PDF to be valid doc.Add(new Paragraph("Hello")); //Close the document doc.Close(); } } } this.Close(); } } } 
+10
source share

The problem with such technologies is that they can never be absolute.

Firstly, this is a security breach for triggering an external event, and software developers probably would not have supported it (or at least I hope not).

Secondly, it depends on things like a network. What happens when someone downloads it and then reads it, for example, offline? You will not receive a notification.

Thirdly, there are several ways to read PDF files. Some people read them with readers you probably haven’t heard of (my favorite is a Linux application that I like a lot better than Adobe AcroRead).

So, even if you could do it (and I would argue that you shouldn't, but that doesn't answer your question), the real answer is no, but even if the software supports it, it still would not be reliable first of all.

+1
source share

Given that PostScript is a fully capable programming language, there should be no reason why you shouldn't keep track of when it is being viewed / executed.

I should think that the hard part of this will be to find the libraries (or make the functions themselves) to do the network part of logging.

A one-time note, however, about such functionality is probably better if you make it still available on failure; the reason is that people tend to get upset when their media suddenly become inaccessible, and this is exactly what will happen if you are forced to stop failing. (Can you guarantee that your registration domain will never change? What will it always be available? What happens when the Internet is not available in the user's situation?)

0
source share

I think I would add to this topic, as it is a bit outdated. An introductory mail script in PDF is a way to "potentially" track a PDF file. However, it has several disadvantages mentioned above.

If you really want to track the opening of PDF files, page views, etc., the easiest and most effective way is to convert the PDF to a web version. You can use free tools for this, such as http://www.pdfonline.com/convert-pdf-to-html/ .

With our Orangedox product , we were able to automatically convert the PDFs stored in Dropbox to the web version using PDF2HTMLEX . After saving as a web version, our PDF viewer can record information, for example, when it was open, how long it was open, what pages were viewed and how long. A much more flexible option than trying to paste codes into a PDF.

0
source share

All Articles