vue-pdf use getTextContent() in forEachPage synchron

41 Views Asked by At

I`m using the vue-pdf plugin (https://www.npmjs.com/package/vue-pdf?activeTab=readme) to display and read a pdf file. Displaying the pdf works so far, reading the text content from the pdf works too, but I want the text from all pages in one variable after reading the pdf. By default, the reading of each page works asynchron and I did not managed it yet to get to work. Here is my code:

<template>
 <pdf ref="file_report_pdf" @loaded="parsePDFInput()"></pdf>
</template>
<script>
import pdf from 'vue-pdf'
export default {
 components: {
  pdf
 },
 methods: {
  parsePDFInput(){
   var full_text = this.$refs.file_report_pdf.page.forEachPage((pdf_page) => {
    return pdf_page.getTextContent().then((pdf_content) => {
     console.log("text",pdf_content.items)
    })
   })
   console.log("full_text",full_text)
  }
 }
}

The important code is the parsePDFInput() method. If I load a pdf, it prints each page of the pdf with the console.log("text",text) command as expected. But I would like to have the text of each page together in the full_text variable. I tried to make the function asynchron and use await to get the promise, but nothing works so far. Anyone have an idea? So far, the full_text is always undefined

0

There are 0 best solutions below