Question: I'm developing an HTML5/JavaScript web application that often runs offline. The user loads a PDF into the application and then has the option to add comments that appear separately to the PDF. I'm using local storage to save any comments made as this works offline rather than using an online database. If the user re-opens the same PDF at a later date I would like to be able to load any previous comments made. To do this, I imagine that I would need to identify something that is unique about the particular PDF so that I can store other values against it in the local storage database. If the user opens the same PDF at a later date, I can query the database to see if comments have been made against that file before and, if so, display them on screen.

Currently I am opening the PDF using `URL.createObjectURL()` which creates a unique blob URL to access the file. This is required as it could be opened offline. My initial thought was that this blob might be used as a unique identifier when stored in the local storage database however the blob understandably changes upon each load and could change if the user moves the location of the PDF on their local machine. For example, opening the same file twice in a row produces: `blob:null/c3ab544d-e16d-cf49-86d8-03c1d67a6ccb` and `blob:null/5ad4b666-e6ba-1a41-a149-d7a77f648261`. 

Is there a way that I can record something unique about the opened file so that I can check if the user re-opens that file at a later date?

Answer: 
Considering that "add comments that appear separately to the PDF" would not affect the file itself (as in, PDF comments embedded in a new version of the file), you could use a hash like md5 to recognize the same file. This is the same method to see if files are corrupted during downloads.

Only caveat is if the browser has access to the file contents through offline-storage due to security concerns.
While it is optional, you may wish to try and use the PDF ID tag. You could probably extract it with some regex against the content. It looks like this: 

```
 /ID[<CDB5FA9499F9C1A71B9784FD77FB5B4D><CDB5FA9499F9C1A71B9784FD77FB5B4D>]

```

From the PDF Specification:

ID

array

(Optional, but strongly recommended; PDF 1.1) An array of two byte-strings constituting a file identifier (see Section 10.3, “File Identifiers”) for the file. The two byte-strings should be direct objects and should be unencrypted. Although this entry is optional, its absence might prevent the file from functioning in some workflows that depend on files being uniquely identified.