npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ifun-vue2/pdf

v0.5.0

Published

pdfjs-dist封装的vu2组件,pdf文件预览

Readme

特点

  • 支持URL、Blob、Base64、ArrayBuffer等格式的PDF文件预览
  • 支持设定缩放比例获得更高的清晰度
  • 支持设置适配容器大小

安装

npm i @ifun-vue2/pdf

使用

import IFunPdf from "@ifun-vue2/pdf";
// 样式
import "@ifun-vue2/pdf/dist/style.css";
// 使用
Vue.use(IFunPdf);

局部注册,导入组件使用:

import { IFunPdf } from "@ifun-vue2/pdf";
// 样式
import "@ifun-vue2/pdf/dist/style.css";

预览数据类型

文件地址url

保证文件url可被访问。地址同源

<template>
  <div>
    <IFunPdf :options="options" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      options: {
        url: pdfUrl,
      },
    };
  },
};
</script>

二进制数据blob\ base64 \ ArrayBuffer

通过data 属性传入二进制数据

<script>
export default {
  data() {
    return {
      options: {
        data: "",
      },
    };
  },
  mounted() {
    
  },
  methods: {
    getPdf() {
      // 文件加载逻辑
      // ... 

      const fileReader = new FileReader();

      fileReader.onload = (event) => {
        let blobData = event.target.result;
        this.options.data = blobData;
      };
      fileReader.readAsArrayBuffer(res.data);
    }
  }
};
</script>

在传入base64数据时,需要通过atobbase64数据转化为blob数据。

<script>
export default {
  methods: {
    getPdf() {
      // 文件加载逻辑
      // ... 
      this.options.data = atob(res.data);
    }
  }
}
</script>

设置页面缩放scale,提高分辨率

设置合适的缩放比例额,可以获得高分辨率的图像。

<template>
  <div>
    <IFunPdf :options="options" :viewportOptions="{ scale: 5 }" />
  </div>
</template>

API 属性一览

| props | 说明 | 默认值 | | ------- | ------------------------------------------- | ------ | | options | 初始化文档对象,同 APIgetDocument参数一致 | | |viewportOptions|pdf页面视口配置,同 API getViewport参数一致|默认{scale: 1}| |fitView|设置渲染是否适配容器大小|默认false,默认为pdf原始大小 |

options

| props | 说明 | 默认值 | | ------- | ------------------------------------------------------------ | ------ | | url | Stringpdf 文档地址,需要同源 | | | data | TypedArray\|ArrayBuffer,二进制数据、base64(需要atob()) | | | ... | 其他可设置参数通pdfjs API参数 | |

viewportOptions

| props | 说明 | 默认值 | | ------- | ------------------------------------------------------------ | ------ | |scale|缩放比例|可调节获得高分辨率的图像,默认 1| |rotation|页面旋转角度|默认 0| |offsetX|页面水平偏移量|默认 0| |offsetY|页面垂直偏移量|默认 0| |...|||

监听事件

| 事件名 | 说明 | | ------ | ------------------------------------------------------------ | | finish | pdf文档加载完成,返回对象,包括 - root:pdf页面父节点;totalPagespdf总页数;clear:清空渲染;getCanvas:获取到pdf的某一页 | | error | pdf文档加载失败,返回错误信息 | | ready | 准备加载pdf文档 |