1.6.2 • Published 7 months ago

@iqx-limited/quick-pdf v1.6.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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 Puppeteer and PDFKit 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 Puppeteer and Firefox.
  • 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 > v20 required.
  • Firefox or Chrome (Module Dependant) either remotely or on your machine.

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:

ParameterTypeDescriptionData that can be passed
inputstring \| URLThe 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.
optionsOptionsOptional configuration for the PDF conversion.An object with optional to configure PDF

Options Type:

PropertyTypeDescriptionDefault
base64booleanPDF should be returned as a base64 encoded string.false
rulesobjectOptional custom validation rules for HTML content - see https://html-validate.org/rules/ for more details. Default is all standard rules enabled.''
closeBrowserbooleanOptional flag to close the browser after conversion.false

2. img2pdf

Function Signature:

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

Parameters:

ParameterTypeDescriptionData that can be passed
inputBuffer \| string \| URLThe 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.
optionsOptionsOptional configuration for the PDF conversion.An object with optional configurations.

Options Type:

PropertyTypeDescriptionDefault
headerstringOptional header text to include in the PDF.undefined
footerstringOptional footer text to include in the PDF.undefined
fontSizenumberFont Size of the header or footer10
closeBrowserbooleanOptional flag to close the browser after conversion.false

3. pdf2img

FIREFOX is a hard requirement. Chrome will not work with this module.

Function Signature:

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

Parameters:

ParameterTypeDescriptionData that can be passed
inputBuffer \| string \| URLThe 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.
optionsOptionsOptional configuration for the image conversion.An object with optional scale, password, and buffer configuration

Options Type:

PropertyTypeDescription
qualitynumberQuality for rendering the PDF pages, not applicable for PNG. Default is 100.
passwordstringOptional password for decrypting password-protected PDFs.
typestringThe mime type to output - "png""jpeg""webp". Default is "png".
pagenumberOptional page number to return. If not specified, all pages are returned.
closeBrowserbooleanOptional flag to close the browser after conversion. Default is false.

3. browsers

Function Signature:

launchBrowser(browserType?: "firefox" | "chrome", wsURL?: string): { browser: Browser; type: string }
closeBrowser()

If no browserType is specified, the first existing instance of a browser will be returned - starting with firefox. If no browser is found, it will try and retrieve the first instance of a browser locally. Where this results in no browser an error will be thrown. If a browserType is specified and no cached browser of that type is found, the browser will attempt to launch from your local machine. Include a wsURL to connect to a remote browser instance. An error will be thrown if not found.

closeBrowser() will close all running browsers, if remote the browser will disconnect. On calling a module without a running instance, the browser will be created automatically - starting with firefox. Pass the closeBrowser parameter to your given module to call closeBrowser() on completion.

1.6.2

7 months ago

1.6.1

7 months ago

1.6.0

7 months ago

1.5.0

7 months ago

1.4.7

7 months ago

1.4.6

9 months ago

1.4.5

9 months ago

1.4.4

9 months ago

1.4.3

9 months ago

1.4.2

9 months ago

1.4.1

10 months ago

1.4.0

11 months ago

1.3.7

11 months ago

1.3.6

11 months ago

1.3.5

11 months ago

1.3.4

11 months ago

1.3.3

11 months ago

1.3.2

11 months ago

1.3.1

11 months ago

1.3.0

11 months ago

1.2.0

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago