Skip to content

Possible to get all pages' dimensions? #166

Answered by TaTo30
shi-yan asked this question in Q&A
Discussion options

You must be logged in to vote

Use the pdf.js api directly.

The pdf value returned by usePDF is a PDFDocumentLoadingTask object, so in your case this should works:

<script setup lang="ts">
import pdf14 from "@samples/45.pdf";
import { usePDF } from "@tato30/vue-pdf";
import { watch } from "vue";

const { pdf, pages } = usePDF(pdf14);

async function getPagesDimensions() {
  const pdfDocument = await pdf.value!.promise!;
  for (let index = 1; index <= pages.value; index++) {
    const pdfPage = await pdfDocument.getPage(index);
    const pageBounds = pdfPage.getViewport({ scale: 1 });
    console.log(pageBounds);
  }
}

watch(pdf, () => {
  getPagesDimensions();
});
</script>

<template>
  <div>Template</div>
</template>

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@shi-yan
Comment options

Answer selected by shi-yan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants