useViewportAutoFitScale

Fits the pages into the viewport once per loaded document: the usual "open at a sensible zoom" behavior, with no wiring.

useViewportAutoFitScale(target)

target is 'width' or 'height': which viewport dimension the pages are fitted into. The fit is applied when a document loads; it doesn't re-apply on later viewport resizes or manual zooming, so the user's zoom choice is respected.

Example

import { useViewportAutoFitScale, Viewport } from '@sdk-pdf/react'

function PdfApplication() {
  useViewportAutoFitScale('width')

  return (
    <div style={{ height: '100vh' }}>
      {/* Throws DocumentNotLoadedError when no document is loaded, since there is nothing
          to show. Render it only when the load state is 'ready'. */}
      <Viewport />
    </div>
  )
}

On this page