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

pdfjs-dist-viewer-angular

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdfjs-dist-viewer-angular

pdfjs-dist non-agnostic language viewer

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
increased by23.08%
Maintainers
1
Weekly downloads
 
Created
Source

Web PDF viewer as a web element

This viewer is a simple pdf viewer based on pdfjs-dist@3.7.107 by Mozilla. This viewer is a non-agnostic web component, which means you can use it in any web application once the script (pdfjs-viewer.js) is imported. It is a refactored version of this example https://mozilla.github.io/pdf.js/examples with annotations, which makes links clickable.

Setting Up

Install the viewer:

npm install --save pdfjs-dist-viewer-angular

Example use

In angular.json

  "scripts": [
    "node_modules/pdfjs-dist-viewer-angular/pdfjs-viewer.js"
  ],
  ...

The pdfjs-viewer.js file has a size of 477kB.

... or lazy loaded (https://angular-extensions.github.io/elements/#/home)

Use web component

In the module where you import the component using the pdfjs-viewer element, you should define the schema.

...
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';

@NgModule({
  declarations: [..],
  imports: [..],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})

In the Angular HTML template

  <pdfjs-viewer [base64]="base64"></pdfjs-viewer>

As native HTML

<html lang="en">
<head>
  <script src="pdfjs-viewer.js"></script>
</head>
<body>
  <pdfjs-viewer url="https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf"></pdfjs-viewer>
</body>
</html>

Options

[url]
PropertyType
[url]*string
[url]{data: atob(JVBERi0xLjQKJeLjz9MK...)}

Pass pdf location

[url]="'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf'"

Or as a BLOB:

[url]="'blob:http://localhost:4200/eb7533b8-d1bf-4bd7-bb6c-e351df579d51'"

base64, just the Base64 value ✓:

  base64 = "JVBERi0xLjQKJeLjz9MKMyAwIG9iagpbL0NhbFJH.. 

Do NOT use a base64 data URI string ✗:

  base64 = "data:application/pdf;base64<JVBERi0xLjQKJeLjz> 
[page]
PropertyTypeRequired
[page]numberOptional

Page number

[page]="1"

If not defined, the viewer shows all pages by default

(rendered)
PropertyTypeRequired
(rendered)callbackOptional

Get event when a page is rendered.

(rendered)="rendered($event)"
(pdfError)
PropertyTypeRequired
(error)callbackOptional

Error handling callback

(error)="onError($event)"

Authors

Keywords

FAQs

Package last updated on 21 Jun 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