@agilehub/vue-pdf-flipbook

A minimal Vue 3 PDF flipbook with page-flip animation and public APIs for external controls.
1,792
Install
npm install @agilehub/vue-pdf-flipbook
Latest Version:2.0.0
Vue:3
License:MIT
Last Updated:Oct 10, 2026
Links: GitHub  ·  npm
Maintainer: liuyuantao

Vue PDF Flipbook Next

基于 Vue 3、PDF.js 和 PageFlip 的 PDF 翻页组件。核心负责 PDF 加载、页面渲染、单页 / 双页布局和点击、拖拽翻页,内置阅读区两侧翻页按钮、首次加载提示和可选的缩略图列表。缩略图可放在书页底部,也可挂载到外部容器;工具栏、缩放、全屏和快捷键由外部实现。组件不依赖 UI 框架。

灵感来源:Paperturn、turnjs。采用 MIT License。

安装

适用于 Vue 3.4+ 项目,Node.js 要求为 22.15+。以下命令任选一个,在调用方项目根目录执行:

pnpm add @agilehub/vue-pdf-flipbook
npm install @agilehub/vue-pdf-flipbook
yarn add @agilehub/vue-pdf-flipbook

包名为 @agilehub/vue-pdf-flipbook,安装、组件导入和类型导入都使用这个完整名称。Vue 是 peer dependency,由业务项目提供;PDF.js 和 Worker 已由组件提供,普通接入不需要额外安装 pdfjs-dist 或复制 Worker。

在应用入口或使用组件的页面引入一次样式:

import '@agilehub/vue-pdf-flipbook/style.css'

在业务页面使用

下面可保存为业务项目中的 PdfReader.vue。它接收 PDF 地址,提供翻页、缩略图开关、错误提示与重试。PDF 地址必须支持 HTTP Range / 206;跨域时还需要 CORS,具体要求见大文件按需预览。

<script setup lang="ts">
import { ref } from 'vue'
import { VuePdfFlipbook } from '@agilehub/vue-pdf-flipbook'
import type { PdfFlipbookExpose, PdfFlipbookState } from '@agilehub/vue-pdf-flipbook'
import '@agilehub/vue-pdf-flipbook/style.css'

const props = defineProps<{ url: string; fileSize?: number }>()
const reader = ref<PdfFlipbookExpose>()
const state = ref<PdfFlipbookState>()
const errorMessage = ref('')

function onError(error: unknown) {
  errorMessage.value = error instanceof Error ? error.message : String(error)
}

function onStateChange(value: PdfFlipbookState) {
  state.value = value
  if (value.loading) errorMessage.value = ''
}
</script>

<template>
  <section class="vpf-example-page">
    <nav class="vpf-example-toolbar" aria-label="阅读工具栏">
      <button :disabled="!state?.canPrevious || state?.pageLoading" @click="reader?.previous()">上一页</button>
      <span>{{ state?.page ?? 1 }} / {{ state?.pages ?? 0 }}</span>
      <button :disabled="!state?.canNext || state?.pageLoading" @click="reader?.next()">下一页</button>
      <button :disabled="!state?.pages || state?.loading" @click="state?.thumbnailsVisible ? reader?.hideThumbnails() : reader?.showThumbnails()">缩略图</button>
    </nav>
    <p v-if="errorMessage" role="alert">
      {{ errorMessage }} <button @click="reader?.reload()">重试</button>
    </p>
    <div class="vpf-example-reader">
      <VuePdfFlipbook
        ref="reader" :url="props.url" :file-size="props.fileSize"
        height="100%" loading-text="文档加载中,请稍候…"
        @state-change="onStateChange" @error="onError"
      />
    </div>
  </section>
</template>

<style scoped>
.vpf-example-page { display: flex; flex-direction: column; width: 100%; height: 80dvh; min-width: 0; min-height: 0; overflow: hidden; }
.vpf-example-toolbar { display: flex; flex: none; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px; }
.vpf-example-reader { flex: 1; min-width: 0; min-height: 0; overflow: hidden; }
</style>

父页面使用这个业务封装,例如在同目录的 App.vue 中:

<script setup lang="ts">
import PdfReader from './PdfReader.vue'
</script>

<template>
  <!-- 将 public/catalog.pdf 替换成你的文件,并确保服务端支持 Range / 206。 -->
  <PdfReader url="/catalog.pdf" />
</template>

也支持全局注册,在业务项目的 main.ts 中使用默认导出:

import { createApp } from 'vue'
import App from './App.vue'
import PdfFlipbook from '@agilehub/vue-pdf-flipbook'
import '@agilehub/vue-pdf-flipbook/style.css'

createApp(App).use(PdfFlipbook).mount('#app')

注册后可直接使用 <VuePdfFlipbook />。需要调用实例方法时,仍应导入 PdfFlipbookExpose 为组件 ref 标注类型。

更多使用说明

完整说明按功能拆分,统一入口见功能文档目录。

功能模块 内容
组件 API Props、事件、实例方法及自适应容器参数
外部容器、缩放与全屏 容器布局、放大缩小、鼠标拖动平移和全屏
PDF 加载、资源与兼容性 HTTP Range、CORS、Worker 和运行时资源管理
插槽与缩略图 插槽 API、覆盖式缩略图、侧栏布局和选中联动
重点标记与锚点批注 标注接入、控制器、按页加载、单条保存和工具栏
笔记内容与外部编辑器 图形与正文分离、富文本和媒体内容的编辑与存储
标注笔记点击事件 仅返回 ID 的点击事件、触发条件和详情查询代码
dev/demo 标注笔记操作流程 流程图、方法参数、调用链、保存与失败处理
常见问题与迁移 入口解析、布局、缩略图、外部 Worker 和旧接口迁移
开发说明 项目组织、开发与验证命令、许可证

Related Packages

@kyle_g/vue-pdf-flipbook

Headless Vue 3 composables for a WebGL PDF flipbook powered by turngl and pdf.js

650 0
vue-pdf-next

基于vite+vue3+pdfjs的pdf预览插件

4,874
@mundogamernetwork/mgn-flipbook

Interactive flipbook component for Vue 3 with page-flip animations, zoom, sound...

3,193
vue-pdf-cdn

Lightweight PDF viewer for Vue.js using CDN

8,142 3
vue3-pdf-app

Vue 3 PDF viewer

518,317 105

Version History

Version Released Vue License
2.0.0 ^3.4.0 MIT
1.3.5 ^3.4.0 MIT
1.3.4 ^3.4.0 MIT
1.3.3 ^3.4.0 MIT
1.3.2 ^3.4.0 MIT