<template>
  <div class="">ContentViewer</div>
</template>
<script>
import { pdfjsLib } from '../../plugins/index'
import { ContentApi } from '../../utils/index'
import { Buffer } from 'buffer'
export default {
  name: 'PdfContentViewer',
  props: {
    content_id: {
      required: true,
      type: String
    }
  },
  components: {},
  computed: {},
  mounted() {
    this.retrieve_blog_content()
  },
  methods: {
    retrieve_blog_content() {
      ContentApi.retrieve_blog_content(this.content_id)
        .then((response) => {
          this.content_media_data = response.data
          var loadingTask = pdfjsLib.getDocument({
            data: Buffer.from(this.content_media_data, 'base64')
          })
          loadingTask.promise.then(function (pdf) {
            //
            // Fetch the first page
            //
            pdf.getPage(1).then(function (page) {
              //rendering
            })
          })
        })
        .catch((error) => {
          this.mnx_backendErrorHandler(error)
        })
    }
  },
  data() {
    return {
      content_media_data: null
    }
  }
}
</script>
