0.0.3 • Published 10 months ago

@develop-plugins/pdf-preview v0.0.3

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

PDF-Preview

简介

PDF预览组件,支持在线预览PDF文件。

安装

npm install @develop-plugins/pdf-preview

引用

import { PDFPreviewInstall } from '@develop-plugins/pdf-preview';
import '@develop-plugins/pdf-preview/style.css';

app.use(PDFPreviewInstall);

属性

参数说明类型默认值
fileUrlPDF文件地址见下表
showPageNumber是否显示页码booleantrue
showToolbar显示工具栏booleantrue
downloadFileName下载文件名string'document.pdf'
watermark水印设置Object见下表

Watermark 配置

参数说明类型默认值
enable是否启用水印booleanfalse
text水印文字string'水印'
fontSize字体大小number16
color字体颜色string'rgba(0, 0, 0, 0.1)'
rotate旋转角度number-30
size水印间距number250

示例

1、属性fileUrlstring类型

<template>
  <PDFPreview :fileUrl="url"/>
</template>

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

// 在线地址或本地地址
const url = ref('/example.pdf');
// base64地址
const url = ref('data:application/pdf;base64,...');
</script>

2、属性fileUrlUint8Array|Blob类型

<template>
  <PDFPreview :fileUrl="base64FileURL"/>
</template>

<script setup>
import { ref } from 'vue';
    
const base64FileURL = ref('');

fetch('/api/file/')
  .then((res) => res.arrayBuffer())
  // .then((res) => res.blob())
  // .then((res) => res.bytes())
  .then((arrayBuffer) => {
    base64FileURL.value = arrayBuffer;
  })
  .catch((err) => {
    console.log(err);
  });
</script>

3、属性fileUrlObject类型

<template>
  <PDFPreview :fileUrl="fileUrl"/>
</template>

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

const fileUrl = ref({
    url: '', // 请求地址
    data: '', // 渲染的数据,如果url和data都有值,以data数据为准
    httpHeaders: {}, // 发送请求头配置
    withCredentials: false // 是否发送认证信息
});
</script>

事件

事件名称说明回调参数
load-successPDF加载成功时触发-
load-errorPDF加载失败时触发error: 错误信息
0.0.3

10 months ago

0.0.2

10 months ago