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

secure-pdf-viewer-vue3

v1.0.0

Published

Secure PDF viewer for Vue 3 - Canvas-only rendering prevents XSS attacks from malicious PDFs

Downloads

100

Readme

secure-pdf-viewer-vue3

A secure PDF viewer component for Vue 3. Uses canvas-only rendering to prevent XSS attacks from malicious PDF files.

Features

  • Canvas-only rendering -- PDF pages are rasterized to <canvas>, no textLayer or annotationLayer DOM elements are created, eliminating all XSS injection vectors
  • JavaScript execution disabled -- isEvalSupported: false prevents PDF.js from executing embedded JavaScript
  • External resource blocking -- disableAutoFetch: true blocks external resource loading (SSRF prevention)
  • Font injection prevention -- disableFontFace: true blocks @font-face injection
  • Built-in toolbar with page navigation and zoom controls
  • Keyboard shortcuts support
  • Three input modes: URL, File object, and ArrayBuffer
  • TypeScript support

Installation

npm install secure-pdf-viewer-vue3 pdfjs-dist

Basic Usage

Load PDF from URL

<template>
  <SecurePdfViewer src="https://example.com/document.pdf" />
</template>

<script setup>
import { SecurePdfViewer } from 'secure-pdf-viewer-vue3';
</script>

Load PDF from File Upload

<template>
  <div>
    <input type="file" accept=".pdf" @change="onFileChange" />
    <SecurePdfViewer v-if="pdfFile" :file="pdfFile" />
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { SecurePdfViewer } from 'secure-pdf-viewer-vue3';

const pdfFile = ref(null);

function onFileChange(e) {
  pdfFile.value = e.target.files[0];
}
</script>

Load PDF from ArrayBuffer

<template>
  <SecurePdfViewer v-if="pdfData" :data="pdfData" />
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { SecurePdfViewer } from 'secure-pdf-viewer-vue3';

const pdfData = ref(null);

onMounted(async () => {
  const response = await fetch('/document.pdf');
  pdfData.value = await response.arrayBuffer();
});
</script>

Full Example

<template>
  <SecurePdfViewer
    ref="viewerRef"
    src="/docs/report.pdf"
    :initial-scale="1.5"
    :show-toolbar="true"
    worker-src="/pdf.worker.min.mjs"
    @page-change="onPageChange"
    @scale-change="onScaleChange"
    @load-state-change="onLoadStateChange"
    @error="onError"
  />
</template>

<script setup>
import { ref } from 'vue';
import { SecurePdfViewer } from 'secure-pdf-viewer-vue3';

const viewerRef = ref(null);

function onPageChange(page, totalPages) {
  console.log(`Page ${page} of ${totalPages}`);
}

function onScaleChange(scale) {
  console.log(`Zoom: ${Math.round(scale * 100)}%`);
}

function onLoadStateChange(state) {
  console.log(`Load state: ${state}`);
}

function onError(error) {
  console.error('PDF error:', error);
}

// Access exposed methods via ref
function jumpToPage5() {
  viewerRef.value?.goToPage(5);
}
</script>

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | src | string | undefined | URL of the PDF file | | file | File | undefined | File object (for file upload scenarios) | | data | ArrayBuffer \| Uint8Array | undefined | Raw PDF data | | initialScale | number | 1.0 | Initial zoom scale | | minScale | number | 0.25 | Minimum zoom scale | | maxScale | number | 5.0 | Maximum zoom scale | | showToolbar | boolean | true | Whether to show the toolbar | | class | string | '' | Custom CSS class for the container | | style | object | {} | Custom inline styles for the container | | workerSrc | string | undefined | Custom path to the PDF.js worker file | | pixelRatio | number | window.devicePixelRatio | Device pixel ratio for rendering | | disableDownload | boolean | false | Disable the download button in toolbar |

Events

| Event | Payload | Description | |-------|---------|-------------| | load-state-change | state: 'idle' \| 'loading' \| 'ready' \| 'error' | Fired when the loading state changes | | page-change | page: number, totalPages: number | Fired when the current page changes | | scale-change | scale: number | Fired when the zoom scale changes | | error | error: Error | Fired when an error occurs |

Exposed Methods

Access these methods via a template ref:

| Method | Signature | Description | |--------|-----------|-------------| | goToPage | (page: number) => void | Navigate to a specific page | | setScale | (scale: number) => void | Set the zoom scale (clamped to min/max) | | getState | () => { currentPage, totalPages, scale } | Get the current viewer state |

Keyboard Shortcuts

When the viewer is focused:

| Key | Action | |-----|--------| | Arrow Left / Arrow Up | Previous page | | Arrow Right / Arrow Down | Next page | | Ctrl + | Zoom in | | Ctrl - | Zoom out |

Security Features

This component is designed with security as the core principle:

  1. No DOM injection -- PDF content is rendered purely to a <canvas> element. No innerHTML, textLayer, or annotationLayer is used, which eliminates all XSS attack vectors from malicious PDFs.

  2. JavaScript execution disabled -- The isEvalSupported: false configuration prevents PDF.js from executing any JavaScript embedded in PDF files.

  3. External resource blocking -- disableAutoFetch: true prevents the PDF from loading external resources, mitigating SSRF attacks.

  4. Font injection prevention -- disableFontFace: true blocks @font-face CSS injection from PDF fonts.

Worker Setup for Production

For production deployments with strict CSP (Content Security Policy), place the pdf.worker.min.mjs file in your public directory and provide its path via the workerSrc prop:

<SecurePdfViewer
  src="/document.pdf"
  worker-src="/pdf.worker.min.mjs"
/>

License

MIT