<!--  -->
<template>
  <div class=""></div>
</template>

<script>
const tempUrl = 'https://zxcloud.oss-cn-hangzhou.aliyuncs.com/pdftax/%E4%B8%AD%E9%9B%84%EF%BC%88%E8%8D%86%E5%B7%9E%EF%BC%89%E4%BF%A1%E6%81%AF%E7%A7%91%E6%8A%80%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8/208688_2024_01_1718707471298.pdf'
// import { getDocument } from "pdfjs-dist/webpack";
// import * as pdfjsLib from "pdfjs-dist/webpack";   // "pdfjs-dist": "^4.7.76",
export default {
  // import引入的组件需要注入到对象中才能使用
  name: 'PDFAnalysis',
  components: {},
  props: {
    // handA: {
    //   type: String,
    //   required: true,
    //   default: '100'
    // }
  },
  data() {
    // 这里存放数据
    return {};
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

    const tempPdf = new this.$PDFAnalysis(tempUrl)
    tempPdf.init()

    // this.extractTextFromPDF(tempUrl)
  },
  // 方法集合
  methods: {
    async extractTextFromPDF(url) {
        console.log('extractTextFromPDF====>',url, pdfjsLib);
        const res =await this.loadPDFBytes(url)
        console.log('pdf arraybuffer====>',res);
        const loadingTask = await pdfjsLib.getDocument({data:res});
        console.log('loadingTask====>',loadingTask);
        const pdf = await loadingTask.promise;
        console.log('pdf====>',pdf);
        
        const page = await pdf.getPage(1);
        console.log('page=====>',page)
        const textContent = await page.getTextContent();
        console.log('textContent====>',textContent);
        
        // console.log(textContent.items.map(item => item.str).join(' '));
    },
    async loadPDFBytes(url){
        const existingPdfBytes = await fetch(url).then(res => res.arrayBuffer())
        return existingPdfBytes
    }
  },
  }
</script>
<style lang='less' scoped>
</style>