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

@iqx-limited/quick-pdf

v1.0.21

Published

Converting PDFs to images (πŸ“ƒ to πŸ“Έ)

Downloads

1,260

Readme

QuickPDF

Handling PDFs in NodeJS (πŸ“ƒ to πŸ–ΌοΈ)

This project provides a set of utilities for converting various file formats without the need for additional dependencies. It supports multiple file types and leverages technologies like Playwright, PDFKit, and pdfjs-dist for file processing.

Features

  • HTML to PDF: Converts HTML content (from a URL or file path) into a PDF.
  • Image to PDF: Converts images (JPEG, PNG) into a PDF, with optional headers and footers.
  • PDF to Image: Converts PDF files to image formats (JPEG or PNG) using pdfjs-dist and canvas.
  • Utilities: Includes helper functions to fetch and read HTML files and read files from local directories.

Requirements

  • Node.js: This project is built with Node.js and uses ES modules. NodeJS > v22 required.
  • Chromium is a dependency of this project, used via Playwright. To install browsers via cli run npx playwright install --with-deps chromium. If running in a ci enviroment you can include --only-shell

Operations Available in the Package

1. html2pdf

Function Signature:

html2pdf(input: string | URL)

Validation occurs on the html string passed. The Error Object returned is:

  {
    valid: boolean,
    count: {
      errors: number,
      warnings: number
    },
    validation: [ {
      file: string,
      count: {
        errors: number,
        warnings: number
      },
      messages: [ {
        message: string,
        line: number,
        column: number,
        ruleId: string
      } ]
    } ]
  }

Parameters:

| Parameter | Type | Description | Data that can be passed | |-----------|---------------|--------------------------------------------------|--------------------------------------------| | input | string \| URL | The HTML content to convert to PDF. | A file path or a URL pointing to HTML content, as either a Node URL object or a Node string. Alternativly pass an html string directly. | | options | Options | Optional configuration for the PDF conversion. | An object with optional to configure PDF |

Options Type:

| Property | Type | Description | Default | |-----------|----------|--------------------------------------------------|---------| | base64 | boolean | PDF should be returned as a base64 encoded string. |false| | rules | object | Optional custom validation rules for HTML content - see https://html-validate.org/rules/ for more details. Default is all standard rules enabled. |''| | scale | number | Scale of the PDF | 1 |

2. img2pdf

Function Signature:

img2pdf(input: Buffer | string | URL, options: Options = {})

Parameters:

| Parameter | Type | Description | Data that can be passed | |-----------|---------------------------|--------------------------------------------------|--------------------------------------------| | input | Buffer \| string \| URL | The image content to convert to PDF. | A Buffer, file path, or URL pointing to an image. String or URL object can be passed for an HTTP or Local Path. | | options | Options | Optional configuration for the PDF conversion. | An object with optional configurations. |

Options Type:

| Property | Type | Description | Default | |-----------|----------|--------------------------------------------------|---------| | header | string | Optional header text to include in the PDF. |undefined| | footer | string | Optional footer text to include in the PDF. |undefined| | fontSize | number | Font Size of the header or footer | 10 |

3. pdf2img

Function Signature:

pdf2img(input: Buffer | string | URL, options: Options = {})

Parameters:

| Parameter | Type | Description | Data that can be passed | |-----------|---------------------------|--------------------------------------------------|--------------------------------------------| | input | Buffer \| string \| URL | The PDF content to convert to images. | A Buffer, file path, or URL pointing to a PDF. String or URL object can be passed for an HTTP or Local Path. | | options | Options | Optional configuration for the image conversion. | An object with optional scale, password, and buffer configuration |

Options Type:

| Property | Type | Description | |-----------|----------------------------------------------------------------------|--------------------------------------------------| | scale | number | Scaling factor for rendering the PDF pages. Default is 1. | | password| string | Optional password for decrypting password-protected PDFs. | | mime | string | The mime type to output - "image/png" | "image/jpeg". Default is "image/png". |