pdf预览兼容问题- chrome浏览器105及一下预览不了

使用的"@tato30/vue-pdf": "^1.11.2"预览插件,发现chrome浏览器105及一下预览不了

pdfPreview预览组件:

html 复制代码
<template>
  <div id="vue_pdf_view">
    <div class="tool_tip">
      <template v-if="pages > 0 && props.previewMode === 'pagination'">
        <button @click="page = page > 1 ? page - 1 : page">上一页</button>
        <span>{{ page }} / {{ pages }}</span>
        <button @click="page = page < pages ? page + 1 : page">下一页</button>
      </template>
      <button @click="handleWord" v-if="fetchWordApi && uniEventId">
        下载word
      </button>
      <button @click="handlePdf" v-if="src && uniEventId">下载PDF</button>
    </div>
    <template v-if="!props.loading && props.previewMode === 'scroll'">
      <div v-for="page in pages" :key="page" class="page">
        <VuePDF :pdf="pdf" :page="page" :scale="scale" />
      </div>
    </template>
    <template v-else-if="!props.loading && props.previewMode === 'pagination'">
      <VuePDF :pdf="pdf" :page="page" />
    </template>
    <template v-else>
      <Spin style="padding-top: 50px"></Spin>
    </template>
  </div>
</template>

<script setup>
import { onMounted, ref } from 'vue';
import { VuePDF, usePDF } from '@tato30/vue-pdf';
import { Spin } from 'ant-design-vue';
import { saveAs } from 'file-saver';

const props = defineProps({
  src: {
    type: String,
  },
  fetchWordApi: {
    type: Function,
  },
  uniEventId: {
    type: String,
  },
  previewMode: {
    // 'pagination','scroll'
    type: String,
    default: 'scroll',
  },
  loading: {
    type: Boolean,
    default: false,
  },
});

const page = ref(1);
const testSrc =
  'https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf';
const { src, fetchWordApi, uniEventId } = props;
const { pdf, pages } = usePDF(src);
const scale = ref(1.5);
const handleWord = () => {
  fetchWordApi &&
    fetchWordApi('docx', { uniEventId }, true).then((res) => {
      const blob = new Blob([res], { type: 'application/msword' });
      saveAs(blob, uniEventId + '.docx');
    });
};

const handlePdf = () => {
  if (!src || !uniEventId) return;
  saveAs(src, uniEventId + '.pdf');
};
</script>

<style lang="scss">
#vue_pdf_view {
  min-height: 1000px;
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  &:hover {
    .tool_tip {
      opacity: 1;
    }
  }
  .tool_tip {
    opacity: 0;
    position: sticky;
    top: 40px;
    left: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1;
    padding: 4px 0;
    border-radius: 4px;
    width: fit-content;
    button {
      padding: 0 10px;
      &:hover {
        color: #555;
      }
    }
  }
  .page {
    padding-bottom: 10px;
  }
}
</style>

使用:

html 复制代码
<pdfPreview
        :loading="loading"
        :key="loading"
        :src="iframeUrl"
        previewMode="scroll"
      ></pdfPreview> 

解决:直接使用iframe的src嵌套pdf即可解决兼容问题

html 复制代码
      <iframe
        :src="`${iframeUrl}#toolbar=0`"
        width="100%"
        height="800px"
        frameBorder="0"
        scrolling="no"
        v-if="loading"
      ></iframe>
相关推荐
林克爱塞尔达7 小时前
Linux入门(二)
linux·运维·chrome
Larry_zhang双栖1 天前
低版本Chrome 内核兼容性问题的优美解决
前端·chrome
allanGold1 天前
【Chrome】chrome 调试工具的network选项卡,如何同时过滤出doc js css
chrome·调试·devtools·技巧·network选项卡
itxh6661 天前
Chrome浏览器 “此扩展程序不再受支持,因此已停用” 解决方案
chrome·插件·chrome浏览器
恣艺1 天前
Redis有序集合(ZSet):排行榜功能的最优解,原理与实战
数据库·chrome·redis
伐尘2 天前
【CE】图形化CE游戏教程通关手册
前端·chrome·游戏·逆向
John_ToDebug2 天前
浏览器稳定性提升之路:线上崩溃率优化中的 Return 与 CHECK 之争
c++·chrome
zhangfeng11332 天前
R geo 然后读取数据的时候 make.names(vnames, unique = TRUE): invalid multibyte string 9
开发语言·chrome·r语言·生物信息
未来之窗软件服务3 天前
浏览器开发CEFSharp (十七)网页自定义下载—仙盟创梦IDE
chrome·浏览器开发·cefsharp·仙盟创梦ide·东方仙盟
John_ToDebug3 天前
Chrome性能黑魔法:深入浅出PGO优化与实战指南
c++·chrome