Loheide-eu-mitarbeiterplatt.../plugins-core/documents/resources/js/pdfThumbnail.js
Friederich Loheide dda250aaad
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m55s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m44s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m25s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m39s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m47s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m51s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m16s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m25s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s
Menü-Editor, farbige Initialen, Seitenköpfe, Favoriten, Vorschaubilder
- Admin → Portal → Menü: Bereiche, Seiten (mit Unterseiten), Links und
  Gruppen mit Unterpunkten, sortierbar, je Rolle einschränkbar;
  Kopfzeile misst den Platz und legt Überzähliges unter „Mehr“
- Initialen in fester Farbe je Person, Abteilungsfarben im Organigramm
- PageHeader für alle Übersichtsseiten
- Dokumente: Favoriten (auch als Startseiten-Kachel), „Häufig genutzt“,
  Vorschaubilder (Bilder, erste PDF-Seite per pdf.js im Browser)
- Platzhalter beim Nachladen

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 13:56:57 +00:00

47 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Erste Seite eines PDFs als kleines Bild – im Browser mit pdf.js, damit der
* Server (Shared Hosting) keine Bildbearbeitung braucht. pdf.js wird erst
* geladen, wenn tatsächlich ein Vorschaubild gebraucht wird.
*/
const cache = new Map();
let library = null;
async function pdfjs() {
library ??= Promise.all([import('pdfjs-dist'), import('pdfjs-dist/build/pdf.worker.min.mjs?url')]).then(([lib, worker]) => {
lib.GlobalWorkerOptions.workerSrc = worker.default;
return lib;
});
return library;
}
export function pdfThumbnail(url, width = 360) {
if (!cache.has(url)) {
cache.set(
url,
(async () => {
const lib = await pdfjs();
const pdf = await lib.getDocument({ url, isEvalSupported: false, enableXfa: false }).promise;
try {
const page = await pdf.getPage(1);
const viewport = page.getViewport({ scale: width / page.getViewport({ scale: 1 }).width });
const canvas = document.createElement('canvas');
canvas.width = Math.round(viewport.width);
canvas.height = Math.round(viewport.height);
await page.render({ canvasContext: canvas.getContext('2d'), viewport }).promise;
return canvas.toDataURL('image/jpeg', 0.82);
} finally {
pdf.destroy();
}
})().catch((error) => {
cache.delete(url);
throw error;
}),
);
}
return cache.get(url);
}