Retrieve document ID in React PDF Viewer

23 Jul 20261 minute to read

This article shows how to retrieve the document ID for a PDF loaded in the React PDF Viewer. The value is held in sessionStorage under the key hashId and is written after a document is loaded, so it is null until a PDF is opened in the viewer.

Refer to the following minimal example that logs the stored document ID when a button is clicked:

<button onclick="uniqueId()">UniqueId</button>

<script>
    // Triggered when the UniqueId button is clicked.
    function uniqueId() {
        //Prints the PDF document id in the console window.
        console.log(window.sessionStorage.getItem("hashId"));
    }
</script>

View sample in GitHub.

See also