美文网首页
word 在线预览

word 在线预览

作者: 莫伊剑客 | 来源:发表于2021-04-19 17:00 被阅读0次
wordBufferToHtml(url) {
      return new Promise(resolve => {
        var xhr = new XMLHttpRequest()
        xhr.open(
          'GET',
          url
        )
        xhr.responseType = 'arraybuffer'
        xhr.onload = function(e) {
          let content = xhr.response
          let blob = new Blob([content], { type: 'application/pdf' })

          let reader = new FileReader()
          reader.readAsArrayBuffer(blob)
          reader.onload = function(loadEvent) {
            var arrayBuffer = xhr.response //arrayBuffer

            mammoth
              .convertToHtml({ arrayBuffer: arrayBuffer })
              .then(displayResult)
              .done()
          }

          function displayResult(result) {
            // document.getElementById("output").innerHTML =result.value;
            let html = result.value
            let newHTML = html.replace(//g, '')
              .replace('<h1>', '<h1 style="text-align: center;">')
              .replace(/<table>/g, '<table style="border-collapse: collapse;">')
              .replace(/<tr>/g, '<tr style="height: 30px;">')
              .replace(/<td>/g, '<td>')
              .replace(/<p>/g, '<p>')
            resolve(newHTML)
          }
        }
        xhr.send()
      })
    }

相关文章

网友评论

      本文标题:word 在线预览

      本文链接:https://www.haomeiwen.com/subject/gvzilltx.html