1.0.7 • Published 8 months ago

llh-pdf v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

以下是PDF组件的使用文档:

ThsPDF 组件文档

简介

ThsPDF 是一个基于 PDF.js 的 Vue3 PDF 查看器组件,提供PDF文件的查看、页面跳转、搜索等功能。

安装

npm install ths-pdf

基础用法

<template>
  <ths-pdf :pdfUrl="pdfUrl" @getSaveResult="handleSaveResult"/>
</template>

<script setup>
import { ref } from 'vue'

const pdfUrl = ref('http://example.com/sample.pdf')

const handleSaveResult = (result) => {
  console.log('保存结果:', result)
}
</script>

属性(Props)

属性名类型默认值说明
pdfUrlString-PDF文件的URL地址

事件(Events)

事件名参数说明
getSaveResultresultObj保存操作的回调函数,返回保存结果对象

方法(Methods)

组件通过 ref 暴露以下方法:

方法名参数说明
getSaveResult-触发文件保存操作
actionChangePagepageNumber跳转到指定页码
actionSearchquery搜索指定内容
actionChangeLocalelangCode切换界面语言

示例代码

页面跳转

<template>
  <ths-pdf ref="pdfRef" :pdfUrl="pdfUrl"/>
  <button @click="jumpToPage(2)">跳转到第2页</button>
</template>

<script setup>
import { ref } from 'vue'

const pdfRef = ref(null)
const pdfUrl = ref('http://example.com/sample.pdf')

const jumpToPage = (pageNum) => {
  pdfRef.value.actionChangePage(pageNum)
}
</script>

搜索内容

<template>
  <ths-pdf ref="pdfRef" :pdfUrl="pdfUrl"/>
  <input v-model="searchText" @keyup.enter="searchContent"/>
</template>

<script setup>
import { ref } from 'vue'

const pdfRef = ref(null)
const searchText = ref('')
const pdfUrl = ref('http://example.com/sample.pdf')

const searchContent = () => {
  pdfRef.value.actionSearch(searchText.value)
}
</script>

注意事项

  1. 确保服务器允许跨域访问PDF文件
  2. PDF文件URL需要是可直接访问的地址
  3. 组件默认占满父容器高度,请确保父容器设置了适当的高度

浏览器兼容性

  • Chrome 60+
  • Firefox 60+
  • Safari 11+
  • Edge 79+

许可证

该组件基于 Apache License 2.0 开源协议。

1.0.7

8 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago