Fit modes
Size pages to the available width, to the whole page, or to their true size, and switch to true size as soon as users zoom.
Basics
fitMode="width" scales pages to fill the width of the document area at the default scale.
Fitting applies only while the scale equals defaultScale. As soon as the user zooms, the page is shown at its true size and the document area scrolls. Reset zoom (0) to fit again.
Fit the whole page
fitMode="page" scales each page so it fits entirely, width and height, which suits slide decks and documents with mixed page sizes.
Shrink only, or true size
Without fitMode, a page wider than the document area is shrunk to fit but never enlarged (fitWidthAtDefaultScale, on by default). Turn it off to always show pages at their true size.
Choosing a mode
| You want | Use |
|---|---|
| Readable text on phones and in narrow columns | the default (shrink only) |
| Documents that use all the space you give them | fitMode="width" |
| Presentations, posters, mixed page sizes | fitMode="page" |
| Pixel-exact 100% (e.g. comparing prints) | fitWidthAtDefaultScale={false} |
Customization
The size of the document area is set by CSS variables, so the same fit mode behaves differently in different layouts.
See --rpv-viewport-max-width, --rpv-viewport-min-height and --rpv-viewport-max-height in the CSS variables reference and the customization guide.
Advanced / escape hatch
PdfPageCanvas takes a fit box ({ width, height, upscale }) so custom layouts can size pages to any container; see FitOptions.
Limitations
- Fitting only happens at the default scale. A controlled
scalethat differs fromdefaultScalealways shows true size. Workaround: setdefaultScaleto the value you control, or reset to it. - Page fit uses the document area’s height. Inline, that area is at most 800px tall (100% of the viewer in fullscreen), so a tall portrait page fits to that height. Workaround: set
--rpv-viewport-max-heightto the height you want to fill.
API
PdfViewerProps— Props for PdfViewer. Every piece of state supports the value / defaultValue / onChange trio.