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

pdf-export-worker

v1.1.0

Published

This package allows you to generate and export PDF files in an efficient, non-blocking way by leveraging Web Workers. By offloading the computationally intensive PDF creation process to a separate thread, the main UI thread remains responsive, ensuring sm

Downloads

127

Readme

pdf-export-worker

pdf-export-worker is a JavaScript library designed to streamline the process of generating large PDF files in the browser efficiently. By utilizing Web Workers and jsPDF, this library handles PDF creation and download without blocking the main thread, allowing for efficient memory management and smooth user experience even when processing extensive data sets.

Features

  • Web Worker Integration: Offloads PDF generation to a background worker to improve performance and prevent UI blocking.
  • Chunked Data Processing: Efficiently processes large datasets by splitting them into manageable chunks.
  • Custom Table Design: Supports customizable table headers, body content, and footers, allowing for well-structured, stylized PDF documents.
  • Memory Management: Releases resources after processing to optimize memory usage.
  • Error Handling: Provides real-time feedback on PDF generation status and handles errors gracefully.

Installation

To install the pdf-export-worker library, use npm or yarn:

npm install pdf-export-worker
# or
yarn add pdf-export-worker

Usage

Basic Setup

In your main JavaScript or TypeScript file, import and call the executePDFGeneratorWorker function to initiate PDF generation.

1. Import the library

import { executePDFGeneratorWorker } from 'pdf-export-worker';

2. Prepare your data

Define the structure of your PDF report data using the TransactionPDFReportType interface.

import { TransactionPDFReportType } from 'pdf-export-worker';

const data: TransactionPDFReportType = { header: ['Column 1', 'Column 2', 'Column 3'], data: [ ['Row 1 Data 1', 'Row 1 Data 2', 'Row 1 Data 3'], // Add more rows as needed ], footer: ['Footer 1', 'Footer 2', 'Footer 3'], };

3. Generate and Download the PDF

Use the executePDFGeneratorWorker function, passing in the data and the desired filename for the PDF

executePDFGeneratorWorker(data, 'SampleReport.pdf') .then(() => console.log('PDF generated and downloaded successfully!')) .catch((error) => console.error('PDF generation failed:', error));

Advanced Configuration

The pdf-export-worker library allows additional customization of the PDF layout, including custom table styling and PDF templating.

Template Customization

The library includes a TemplateDesign class, which can be used to apply specific design templates for your PDF tables.

API Reference

executePDFGeneratorWorker(data: TransactionPDFReportType, fileName: string): Promise<void>

Initiates PDF generation in a Web Worker, handling large datasets by chunking and efficient memory management.

  • Parameters :
  • data: TransactionPDFReportType - Data for the PDF report, including header, body, and footer.
  • fileName: string - Name of the PDF file to be downloaded.
  • Returns : Promise<void> - Resolves when the PDF is successfully generated and downloaded.

generatePDF(data: TransactionPDFReportType, existingDoc?: jsPDF): ArrayBuffer

Generates a PDF document based on the provided data and optional existing jsPDF instance.

  • Parameters :
  • data: TransactionPDFReportType - Data for the PDF report.
  • existingDoc: jsPDF (optional) - Existing jsPDF document instance for appending content.
  • Returns : ArrayBuffer - PDF content in ArrayBuffer format.

TemplateDesign

Class for creating template designs to apply consistent styles and formatting to the PDF document.

Error Handling

  • Status Messages : The worker communicates progress via status messages (processing, completed, or error).
  • Error Messages : Any issues encountered during processing are sent to the main thread for handling and user notification.

Example

Below is an example setup that uses pdf-export-worker for generating a large PDF report with customized headers, footers, and efficient background processing:

Dependencies

  • jsPDF : A JavaScript library for generating PDF documents.
  • jsPDF-AutoTable : Extends jsPDF with support for adding tables with custom headers and footers.

License

This library is MIT licensed.