PDF.js inline module through Joomla WebAssetManager

WT PDF.js - Documentation

Use addInlineScript() with a dependency and type="module" .

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']
);

WebTolk Joomla Extensions

113 Extensions
12 Categories
582 Versions released
893721 Downloads