← All Components
<mth-pdf-viewer>
Wrap-first Mozilla pdf.js <mth-pdf-viewer> component supporting page navigation, zoom presets, text search, document outline, URL sanitization, keyboard/RTL navigation, and <slot name="fallback">.
When NOT to use: Use a lightweight @methane-ui/css layout class instead of a custom element when static CSS suffices.
Live Interactive Preview
Ready · interact with <mth-pdf-viewer>, or toggle Theme, Direction (LTR/RTL), or props above.
Multi-Framework Playground & Snippets
<script type="module" src="@methane-ui/pdf/pdf-viewer"></script>
<mth-pdf-viewer page="1" total-pages="0"></mth-pdf-viewer>import '@methane-ui/pdf/pdf-viewer';
import '@methane-ui/react';
export function Example() {
return <mth-pdf-viewer page="1" total-pages="0"></mth-pdf-viewer>;
}<script setup lang="ts">
import '@methane-ui/pdf/pdf-viewer';
</script>
<template>
<mth-pdf-viewer page="1" total-pages="0"></mth-pdf-viewer>
</template>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@methane-ui/pdf/pdf-viewer';
import { MthPdfViewerDirective } from '@methane-ui/angular';
@Component({
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [MthPdfViewerDirective],
template: `<mth-pdf-viewer page="1" total-pages="0"></mth-pdf-viewer>`,
})
export class ExampleComponent {}<script lang="ts">
import '@methane-ui/pdf/pdf-viewer';
import MthPdfViewer from '@methane-ui/svelte/MthPdfViewer.svelte';
</script>
<MthPdfViewer page="1" total-pages="0"></MthPdfViewer>Properties & Attributes
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
src | src | string | "" | URL to PDF document (validated with @methane-ui/sanitize isSafeUrl). |
workerSrc | worker-src | string | "" | Optional custom pdf.js worker script URL. Strongly recommended in production to keep pdf.js parsing off the main thread and prevent bundling pdf.worker.mjs (~several hundred KB) into app lazy chunks. |
documentTitle | document-title | string | "" | Accessible PDF title shown in viewer label. |
page | page | number | 1 | 1-based active page number. |
totalPages | total-pages | number | 0 | Total page count reported by pdf.js. |
zoom | zoom | number | 'auto' | 'page-fit' | 'page-width' | 1 | Numeric scale or preset (auto, page-fit, page-width). |
rotation | rotation | 0 | 90 | 180 | 270 | 0 | Page rotation angle in degrees (0, 90, 180, 270). |
searchQuery | search-query | string | "" | Search term highlighted/counted across extracted page text. |
showOutline | show-outline | boolean | false | Controls visibility of the PDF outline panel. |
showToolbar | show-toolbar | boolean | true | Controls visibility of the viewer toolbar. |
loading | loading | boolean | false | Displays accessible loading state. |
error | error | string | "" | Human-readable error message when PDF loading fails. |
data | — | Uint8Array | ArrayBuffer | null | — | Raw PDF binary bytes passed directly via JS property. |
Events
| Event | Detail Type | Description |
|---|---|---|
mth-pdf-load | { numPages: number; title: string } | Emitted when the PDF document finishes loading. |
mth-page-change | { page: number; totalPages: number } | Emitted when active page index changes. |
mth-zoom-change | { zoom: number | 'auto' | 'page-fit' | 'page-width' } | Emitted when zoom level or preset changes. |
mth-search-change | { query: string; matchCount: number } | Emitted when search query runs against extracted text. |
mth-pdf-error | { message: string } | Emitted on unsafe URL or pdf.js load failure. |
APG Keyboard Matrix
| Key | Direction | When | Expected Behavior |
|---|---|---|---|
| PageDown | both | viewer viewport is focused | advances to the next PDF page |
| PageUp | both | viewer viewport is focused | returns to the previous PDF page |
| ArrowRight | ltr | viewer viewport is focused | advances to the next PDF page |
| ArrowLeft | rtl | viewer viewport is focused | advances to the next PDF page in RTL |
| Home | both | viewer viewport is focused | jumps to page 1 |
| End | both | viewer viewport is focused | jumps to the last page |
Accessibility Checklist
| Category | Requirement | Verified By |
|---|---|---|
| aria | All aria-* IDREFs resolve within the same DOM root (ADR-003). | scanSameRootAria |
| focus | delegatesFocus: true with zero host internals.role (ADR-014). | lint-plugin & spec-compiler |
| contrast | Renders legible borders, focus outlines, and selection indicators under forced-colors: active. | Playwright forced-colors matrix |
| keyboard | Implements all 6 APG keyboard transitions across LTR/RTL. | mth-pdf-viewer.spec.test.ts |
| states | Exposes ElementInternals CustomStateSet flags: :state(loading), :state(error), :state(has-document), :state(outline-open), :state(reduced-motion). | Conformance suite |
| i18n | Routes 19 UI/ARIA strings through @methane-ui/core i18n catalog. | Locale context test |