Methane@methane-ui/*
CSS LayoutsComponentsSkillsTheme BuilderGitHub
← All Components

<mth-pdf-viewer>

@methane-ui/pdf~9.0 KB brotli shell + lazy engine~2.6 KB shell · lazy engine chunk

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

Interactive StageLive Custom Element · <mth-pdf-viewer> (@methane-ui/pdf)
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>

Properties & Attributes

PropertyAttributeTypeDefaultDescription
srcsrcstring""URL to PDF document (validated with @methane-ui/sanitize isSafeUrl).
workerSrcworker-srcstring""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.
documentTitledocument-titlestring""Accessible PDF title shown in viewer label.
pagepagenumber11-based active page number.
totalPagestotal-pagesnumber0Total page count reported by pdf.js.
zoomzoomnumber | 'auto' | 'page-fit' | 'page-width'1Numeric scale or preset (auto, page-fit, page-width).
rotationrotation0 | 90 | 180 | 2700Page rotation angle in degrees (0, 90, 180, 270).
searchQuerysearch-querystring""Search term highlighted/counted across extracted page text.
showOutlineshow-outlinebooleanfalseControls visibility of the PDF outline panel.
showToolbarshow-toolbarbooleantrueControls visibility of the viewer toolbar.
loadingloadingbooleanfalseDisplays accessible loading state.
errorerrorstring""Human-readable error message when PDF loading fails.
data—Uint8Array | ArrayBuffer | null—Raw PDF binary bytes passed directly via JS property.

Events

EventDetail TypeDescription
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

KeyDirectionWhenExpected Behavior
PageDownbothviewer viewport is focusedadvances to the next PDF page
PageUpbothviewer viewport is focusedreturns to the previous PDF page
ArrowRightltrviewer viewport is focusedadvances to the next PDF page
ArrowLeftrtlviewer viewport is focusedadvances to the next PDF page in RTL
Homebothviewer viewport is focusedjumps to page 1
Endbothviewer viewport is focusedjumps to the last page

Accessibility Checklist

CategoryRequirementVerified By
ariaAll aria-* IDREFs resolve within the same DOM root (ADR-003).scanSameRootAria
focusdelegatesFocus: true with zero host internals.role (ADR-014).lint-plugin & spec-compiler
contrastRenders legible borders, focus outlines, and selection indicators under forced-colors: active.Playwright forced-colors matrix
keyboardImplements all 6 APG keyboard transitions across LTR/RTL.mth-pdf-viewer.spec.test.ts
statesExposes ElementInternals CustomStateSet flags: :state(loading), :state(error), :state(has-document), :state(outline-open), :state(reduced-motion).Conformance suite
i18nRoutes 19 UI/ARIA strings through @methane-ui/core i18n catalog.Locale context test