Load inline code with an asset dependency
Use addInlineScript() with a dependency and type="module". The dependency activates the library. A non-module inline script may run before PDF.js. Pass user data through script options instead of interpolating unchecked strings into JavaScript.
PHP example
<?php
use Joomla\CMS\Factory;
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->addInlineScript(
"window.addEventListener('DOMContentLoaded', () => { console.log(globalThis.pdfjsLib.version); }, { once: true });",
['name' => 'com_example.pdf-version'],
['type' => 'module'],
['wt-pdf-js-legacy']
);