Skip to content

Methods ​

The viewer exposes imperative methods on its component instance. Access the instance through a template ref and call the methods directly:

vue
<script setup lang="ts">
import { ref } from 'vue'
import { PdfViewer } from 'vue-pdfz'

const viewer = ref<InstanceType<typeof PdfViewer>>()
</script>

<template>
  <PdfViewer ref="viewer" source="/document.pdf" />
</template>
MethodSignatureDescription
goToPage(page: number) => voidScroll to and activate a page.
nextPage / prevPage() => voidMove one page forward / back.
setZoom(zoom: ZoomValue) => voidSet a numeric scale or a fit mode.
zoomIn / zoomOut() => voidStep the zoom by zoomStep.
rotate(direction: 'cw' | 'ccw') => voidRotate 90° clockwise / counter-clockwise.
search(query: string, options?: SearchOptions) => Promise<void>Run a search; options is a SearchOptions object.
nextMatch / prevMatch() => voidJump to the next / previous match.
clearSearch() => voidClear the query and highlights.
print() => Promise<void>Print the document.
download(filename?: string) => Promise<void>Download the document (form values baked in).

Example ​

ts
viewer.value.goToPage(3)
viewer.value.setZoom('page-width')
viewer.value.rotate('cw')
await viewer.value.search('invoice', { caseSensitive: true })
viewer.value.nextMatch()
await viewer.value.download('report.pdf')