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

ts-pdf-image-manager

v1.4.0

Published

A TypeScript library for managing images, editing them, and exporting to PDF with a simple API

Readme

ts-pdf-image-manager

A TypeScript library for managing images, editing them, and exporting to PDF — all via a simple API.

Features

  • Simple API — Initialize with a single container ID
  • Drag & Drop reorder — Native HTML5 API for reordering images
  • Image Editor — Full-screen dialog with Crop, Crop Remaining, Rotate, Flip, Mirror, Undo, Reset
    • Save and Save & Close buttons
    • Previous/Next navigation to edit multiple images without closing
    • Unsaved changes detection with confirmation dialog
    • Toast notification on save
  • PDF Export — Pure TypeScript binary PDF generation
  • File modal — Drag-and-drop or browse to add files
    • Option to skip modal and show file dialog directly
  • Thumbnail Actions — Edit and delete icons on hover (optional)
  • Scoped styles — CSS with pim- prefix, injected programmatically
  • TypeScript support — Full type definitions included

Installation

npm install ts-pdf-image-manager

Quick Start

import { TsPdfImageManager } from 'ts-pdf-image-manager';

const pdfManager = new TsPdfImageManager();

// Initialize the library
pdfManager.init('my-container', {
  onPdfGenerated: (blob: Blob) => {
    const url = URL.createObjectURL(blob);
    window.open(url, '_blank');
  },
  onFilesChanged: (files) => {
    console.log('Files:', files.length);
  }
});

// Clean up when done
pdfManager.destroy('my-container');

HTML Setup

<div id="my-container" style="height: 500px; border: 1px solid #ddd;"></div>

API

TsPdfImageManager

init(containerId: string, options?: PdfManagerOptions): ManagerShell | undefined

Initialize the library inside the given element ID.

destroy(containerId: string): void

Tear down the library, remove all DOM and injected styles.

getInstance(containerId: string): ManagerShell | undefined

Get the manager instance for a specific container.

updateOptions(containerId: string, options: Partial<PdfManagerOptions>): void

Update options for an existing instance.

getFiles(containerId: string): PdfImageItem[]

Returns current list of files managed by the given container.

edit(containerId: string): void

Open the editor for the selected image.

add(containerId: string): void

Open the file add modal.

remove(containerId: string): void

Remove the selected image.

removeAll(containerId: string, force?: boolean): void

Remove all images from the container.

addFromDataUrl(containerId: string, dataUrl: string, name?: string): void

Add an image from a base64 data URL string.

// Example with base64 data URL
const base64DataUrl = 'data:image/png;base64,iVBORw0KGgoAAAANS...';
pdfManager.addFromDataUrl('my-container', base64DataUrl, 'my-image.png');

// Example with dynamic format
const dataUrl = 'data:image/' + format + ';base64,' + base64Payload;
pdfManager.addFromDataUrl('my-container', dataUrl, 'scanned-image.' + format);

PdfManagerOptions

interface PdfManagerOptions {
  onPdfGenerated?: (blob: Blob) => void;
  onFilesChanged?: (files: PdfImageItem[]) => void;
  acceptedTypes?: string[];        // default: image/* + application/pdf
  maxFiles?: number;               // default: unlimited
  showToolbar?: boolean;           // default: true
  showLeftPanelAdd?: boolean;      // default: true
  showFileDetails?: boolean;       // default: true
  showDragAndDropModal?: boolean; // default: true (show modal) / false (direct file dialog)
  showThumbnailActions?: boolean;  // default: false (show edit/delete icons on hover)
}

PdfImageItem

interface PdfImageItem {
  id: string;
  name: string;
  type: 'image' | 'document';
  originalFile?: File;  // optional when adding from data URL
  dataUrl: string;
  editedDataUrl?: string;  // set after editing
  order: number;
}

Usage Example

import { TsPdfImageManager } from 'ts-pdf-image-manager';

class MyApp {
  private pdfManager = new TsPdfImageManager();

  constructor() {
    this.initialize();
  }

  private initialize() {
    const container = document.getElementById('pdf-manager');
    if (!container) return;

    this.pdfManager.init('pdf-manager', {
      onPdfGenerated: (blob: Blob) => {
        // Handle generated PDF
        this.downloadPdf(blob);
      },
      onFilesChanged: (files) => {
        // Handle file changes
        console.log('Current files:', files);
      },
      acceptedTypes: ['image/*', 'application/pdf'],
      maxFiles: 10,
      showDragAndDropModal: false,  // Skip modal, show file dialog directly
      showThumbnailActions: true     // Show edit/delete icons on thumbnail hover
    });
  }

  private downloadPdf(blob: Blob) {
    const url = URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = 'document.pdf';
    a.click();
    URL.revokeObjectURL(url);
  }

  destroy() {
    this.pdfManager.destroy('pdf-manager');
  }
}

Advanced Features

Thumbnail Actions

Enable edit and delete icons on thumbnail hover:

pdfManager.init('container', {
  showThumbnailActions: true  // Show edit/delete icons on hover
});

Direct File Dialog

Skip the drag-and-drop modal and show the file dialog directly:

pdfManager.init('container', {
  showDragAndDropModal: false  // Show file dialog instead of modal
});

Browser Support

Any modern browser with support for:

  • Canvas API
  • FileReader API
  • HTML5 Drag and Drop
  • ES2020

Dependencies

  • jQuery (peer dependency)

Development

# Install dependencies
npm install

# Build the library
npm run build

# The built files will be in the dist/ directory

License

MIT © 2024

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.