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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-pdf

v0.12.0

Published

PDF.js-based PDF viewer

Downloads

120

Readme

ts-pdf 📄

Features

How it works in a nutshell

PDF file source data (decrypted if needed) is parsed using the custom parser written from scratch. Annotations of all the supported types are extracted from the source file. The resulting PDF file (without the supported annotations) is handled by the PDF.js worker, which is used to render the file contents and build a text layer. The extracted annotations are rendered to SVG on top of the pages by the custom PDF appearance stream renderer. User can modify or delete any supported annotation or add new annotations of the supported types by using provided UI. The annotations can be imported or exported at any time using corresponding methods. All changes are made can be saved to a new PDF file, which can be downloaded or returned to the caller as a byte array.

Currently supported annotation types

Currently supported PDF encryption algorithms

Yet to be implemented

Currently supported PDF stream encoding algorithms

Not implemented yet

Getting started

Installation into your project

npm install ts-pdf

Running the simplest example

import { TsPdfViewer, TsPdfViewerOptions } from "ts-pdf";

async function run(): Promise<void> {  
  const options: TsPdfViewerOptions = {
    containerSelector: "#your-html-container-selector", 
    workerSource: "assets/pdf.worker.min.js", // path to the PDF.js worker script
    userName: "your_username",
    // you can check other properties using your editor hints
  };
  const viewer = new TsPdfViewer(options);
  await viewer.openPdfAsync("your_file.pdf");
} 

run();

⚠️for viewer to function properly its container element must have relative, absolute or fixed position!

Changing the color scheme

To apply a custom color scheme to the viewer, assign color values to the following CSS variables. Default values are used for omitted variables.

:root {
  --tspdf-color-primary: rgba(77, 88, 115, 1);
  --tspdf-color-primary-tr: rgba(77, 88, 115, 0.9);
  --tspdf-color-secondary: rgb(113, 133, 150);
  --tspdf-color-secondary-tr: rgba(113, 133, 150, 0.9);
  --tspdf-color-accent: rgba(64, 72, 95, 1);
  --tspdf-color-shadow: rgba(0, 0, 0, 0.75);
  --tspdf-color-bg: rgba(128, 128, 128,1);
  --tspdf-color-fg-primary: rgba(255, 255, 255, 1);
  --tspdf-color-fg-secondary:rgba(187, 187, 187, 1);
  --tspdf-color-fg-accent: rgb(255, 204, 0);
  --tspdf-color-text-selection: rgba(104, 104, 128, 0.3);
}

Keyboard shortcuts

Solving Angular app compilation issue

When using this module inside an Angular app you can face the problem that your project is not compiling because of 'SyntaxError: Unexpected token'. The cause of such behavior is that Angular 11.x and lower use Webpack v4.x that does not support fluent null-check syntax ('?.'), which is present in 'pdfjs-dist' build. The easy solution is to replace

"main": "build/pdf.js" 

with

"main": "es5/build/pdf.js" 

inside

"/node_modules/pdfjs-dist/package.json"

The other one is to make your own build of PDF.js.

TODO list

External dependencies:

Running the demo

Additional information