Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dbp-toolkit/pdf-viewer

Package Overview
Dependencies
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dbp-toolkit/pdf-viewer

PDF Viewer Web Component

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

PdfViewer Web Component

GitHub | NPM

This component is a wrapper around the pdf.js library to display PDF files in the browser.

You can install this component via npm:

npm i @dbp-toolkit/pdf-viewer

Usage

<dbp-pdf-viewer></dbp-pdf-viewer>
<script type="module" src="node_modules/@dbp-toolkit/pdf-viewer/dist/dbp-pdf-viewer.js"></script>

Or directly via CDN:

<dbp-pdf-viewer></dbp-pdf-viewer>
<script type="module" src="https://unpkg.com/@dbp-toolkit/pdf-viewer@0.0.2/dist/dbp-pdf-viewer.js"></script>

Attributes

  • lang (optional, default: de): set to de or en for German or English
    • example <dbp-pdf-viewer lang="de" client-id="my-client-id"></dbp-pdf-viewer>

Methods

  • showPDF(file: File): Opens a PDF file. The file must be a File object.
    • example document.querySelector('dbp-pdf-viewer').showPDF(file);

Screenshot

screenshot

Opening a PDF file

You can use the showPDF method to open a PDF file. This method accepts a File object as parameter.

<input @change=${this.openFile} type="file" />
<dbp-pdf-viewer lang="en"></dbp-pdf-viewer>
<script type="module" src="https://unpkg.com/@dbp-toolkit/pdf-viewer@0.0.2/dist/dbp-pdf-viewer.js"></script>

<script>
  document.querySelector('input').addEventListener('change', function(e) {
    if (e.target.files[0]) {
      let file = e.target.files[0];

      console.log('You selected ' + file.name);
      document.querySelector('dbp-pdf-viewer').showPDF(file);
    }
  });
</script>

See example/index.html for a working example.

Local development

# get the source
git clone git@github.com:digital-blueprint/toolkit.git
cd toolkit/packages/pdf-viewer

# install dependencies
yarn install

# constantly build dist/bundle.js and run a local web-server on port 8002 
yarn run watch

# run tests
yarn test

# build local packages in dist directory
yarn run build

Jump to http://localhost:8002 and you should get a demo page.

FAQs

Package last updated on 04 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc