diff --git a/components/PDFViewer.vue b/components/PDFViewer.vue index 26a4e3d..6bf2b71 100644 --- a/components/PDFViewer.vue +++ b/components/PDFViewer.vue @@ -34,11 +34,151 @@ onMounted(() => loadPdf(props.fileId)) watch(() => props.fileId, (newPath) => { if (newPath) loadPdf(newPath) }) + +const vpvRef = ref(null); + +//Zoom Control +const zoomControl = computed(() => vpvRef.value?.zoomControl) + +const currentScale = computed(() => { + return zoomControl.value?.scale +}) + +const handleZoomTool = (type) => { + const zoomCtrl = unref(zoomControl) + if (!zoomCtrl) return + + const scale = unref(currentScale) + if (type === "in") { + scale && zoomCtrl.zoom(scale + 0.25) + } else if (type === "out") { + scale && zoomCtrl.zoom(scale - 0.25) + } else { + zoomCtrl.zoom(type) + } +} + +//Page Control +const pageControl = computed(() => vpvRef.value?.pageControl) +const currentPageInput = computed(() => pageControl.value?.currentPage) +const searchControl = computed(() => vpvRef.value?.searchControl) +const totalMatches = computed(() => searchControl.value?.searchMatches?.totalMatches) + +const isNextPageButtonDisable = computed(() => + pageControl.value?.currentPage === pageControl.value?.totalPages +) + +const isPreviousPageButtonDisable = computed(() => + pageControl.value?.currentPage === 1 +) + +const prevPage = () => { + const isFirstPage = pageControl.value?.currentPage === 1 + if (isFirstPage) return + pageControl.value?.goToPage(pageControl.value?.currentPage - 1) +} + +const nextPage = () => { + const isLastPage = pageControl.value?.currentPage === pageControl.value?.totalPages + if (isLastPage) return + pageControl.value?.goToPage(pageControl.value?.currentPage + 1) +} + +const handleKeyPress = (event) => { + if (event.key === "Enter") { + handlePageInput(event) + } +} + +//Handle Download +const downloadControl = computed(() => vpvRef.value?.downloadControl) + +const handleDownloadFile = () => { + const downloadCtrl = unref(downloadControl) + if (!downloadCtrl) return + downloadCtrl.download() +} + +watch(downloadControl, (downloadCtrl) => { + if (!downloadCtrl) return + + downloadCtrl.onError = (error) => { + console.log("Download error", error) + } + + downloadCtrl.onComplete = () => { + console.log("Download completed") + } +}) +