Skip to content

Page Controller >=1.5.0

pageControl

NameDescriptionType
goToPageTo force the viewer to go to a certain page(page: number) => void
currentPageReturns the page number of the current pagenumber
totalPagesReturns the total number of pages for a PDF documentnumber
vue
<script setup lang="ts">
import { VPdfViewer } from '@vue-pdf-viewer/viewer'
import { ref, computed } from 'vue'

// Create a ref to hold the VPdfViewer component
const vpvRef = ref<InstanceType<typeof VPdfViewer>>()
const pageControl = computed(() => vpvRef.value?.pageControl)

const nextPage = () => {
  const isLastPage = pageControl.value?.currentPage === pageControl.value?.totalPages
  if (isLastPage) {
    return
  }
  pageControl.value?.goToPage(pageControl.value?.currentPage + 1)
}

const prevPage = () => {
  const isFirstPage = pageControl.value?.currentPage === 1
  if (isFirstPage) {
    return
  }
  pageControl.value?.goToPage(pageControl.value?.currentPage - 1)
}

const afterGoToPage = (page: number) => {
  console.log('Current page is: ', page)
}
</script>

<template>
  <div id="vpv">
    <div>
      <button @click="prevPage">Prev</button>
    </div>
    <div>
      <button @click="nextPage">Next</button>
    </div>
    <div :style="{ width: '100%', height: '100%' }">
      <VPdfViewer
        ref="vpvRef"
        src="https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf"
        @afterGoToPage="afterGoToPage"
      />
    </div>
  </div>
</template>
<style scoped>
#vpv {
  width: 100%;
  height: 1490px;
  margin: 0 auto;
}
@media (max-width: 992px) {
  #vpv {
    width: 85%;
  }
}
@media (max-width: 1028px) {
  #vpv {
    width: 70%;
  }
}
</style>
vue
<script setup>
import { VPdfViewer } from '@vue-pdf-viewer/viewer'
import { ref, computed } from 'vue'

// Create a ref to hold the VPdfViewer component
const vpvRef = ref(null)
const pageControl = computed(() => vpvRef.value?.pageControl)

const nextPage = () => {
  const isLastPage = pageControl.value?.currentPage === pageControl.value?.totalPages
  if (isLastPage) {
    return
  }
  pageControl.value?.goToPage(pageControl.value?.currentPage + 1)
}

const prevPage = () => {
  const isFirstPage = pageControl.value?.currentPage === 1
  if (isFirstPage) {
    return
  }
  pageControl.value?.goToPage(pageControl.value?.currentPage - 1)
}

const afterGoToPage = (page) => {
  console.log('Current page is: ', page)
}
</script>

<template>
  <div id="vpv">
    <div>
      <button @click="prevPage">Prev</button>
    </div>
    <div>
      <button @click="nextPage">Next</button>
    </div>
    <div :style="{ width: '100%', height: '100%' }">
      <VPdfViewer
        ref="vpvRef"
        src="https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf"
        @afterGoToPage="afterGoToPage"
      />
    </div>
  </div>
</template>
<style scoped>
#vpv {
  width: 100%;
  height: 1490px;
  margin: 0 auto;
}
@media (max-width: 992px) {
  #vpv {
    width: 85%;
  }
}
@media (max-width: 1028px) {
  #vpv {
    width: 70%;
  }
}
vue
<script lang="ts">
import { VPdfViewer } from '@vue-pdf-viewer/viewer'
import { ref, computed, defineComponent } from 'vue'

export default defineComponent({
  components: { VPdfViewer },
  setup() {
    // Create a ref to hold the VPdfViewer component
    const vpvRef = ref<InstanceType<typeof VPdfViewer>>()
    const pageControl = computed(() => vpvRef.value?.pageControl)

    const nextPage = () => {
      const isLastPage = pageControl.value?.currentPage === pageControl.value?.totalPages
      if (isLastPage) {
        return
      }
      pageControl.value?.goToPage(pageControl.value?.currentPage + 1)
    }

    const prevPage = () => {
      const isFirstPage = pageControl.value?.currentPage === 1
      if (isFirstPage) {
        return
      }
      pageControl.value?.goToPage(pageControl.value?.currentPage - 1)
    }

    const afterGoToPage = (page: number) => {
      console.log('Current page is: ', page)
    }

    return {
      vpvRef,
      nextPage,
      prevPage,
      afterGoToPage
    }
  }
})
</script>

<template>
  <div id="vpv">
    <div>
      <button @click="prevPage">Prev</button>
    </div>
    <div>
      <button @click="nextPage">Next</button>
    </div>
    <div :style="{ width: '100%', height: '100%' }">
      <VPdfViewer
        ref="vpvRef"
        src="https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf"
        @afterGoToPage="afterGoToPage"
      />
    </div>
  </div>
</template>
<style scoped>
#vpv {
  width: 100%;
  height: 1490px;
  margin: 0 auto;
}
@media (max-width: 992px) {
  #vpv {
    width: 85%;
  }
}
@media (max-width: 1028px) {
  #vpv {
    width: 70%;
  }
}
vue
<script>
import { VPdfViewer } from '@vue-pdf-viewer/viewer'
import { ref, computed } from 'vue'

export default {
  components: { VPdfViewer },
  setup() {
    // Create a ref to hold the VPdfViewer component
    const vpvRef = ref()
    const pageControl = computed(() => vpvRef.value?.pageControl)

    const nextPage = () => {
      const isLastPage = pageControl.value?.currentPage === pageControl.value?.totalPages
      if (isLastPage) {
        return
      }
      pageControl.value?.goToPage(pageControl.value?.currentPage + 1)
    }

    const prevPage = () => {
      const isFirstPage = pageControl.value?.currentPage === 1
      if (isFirstPage) {
        return
      }
      pageControl.value?.goToPage(pageControl.value?.currentPage - 1)
    }

    const afterGoToPage = (page) => {
      console.log('Current page is: ', page)
    }

    return {
      vpvRef,
      nextPage,
      prevPage,
      afterGoToPage
    }
  }
}
</script>

<template>
  <div id="vpv">
    <div>
      <button @click="prevPage">Prev</button>
    </div>
    <div>
      <button @click="nextPage">Next</button>
    </div>
    <div :style="{ width: '100%', height: '100%' }">
      <VPdfViewer
        ref="vpvRef"
        src="https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf"
        @afterGoToPage="afterGoToPage"
      />
    </div>
  </div>
</template>
<style scoped>
#vpv {
  width: 100%;
  height: 1490px;
  margin: 0 auto;
}
@media (max-width: 992px) {
  #vpv {
    width: 85%;
  }
}
@media (max-width: 1028px) {
  #vpv {
    width: 70%;
  }
}