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

node-qpdf

v1.0.3

Published

A Content Preserving transformations on PDFs wrapped around QPDF

Downloads

18,677

Readme

node-qpdf

npm version NPM Downloads NPM Downloads bitHound Code bitHound Overall Score

A very simple wrapper for qpdf which is a content-preserving transformations on PDF files. It includes encrypting and decrypting PDF with AES 256, AES 128, RC4 (128 & 40) encryption algorithms.

Dependencies

Installation

  1. Install qpdf:
  2. Install node-qpdf:
    npm install node-qpdf

Encryption

You can encrypt your PDF by following:

var qpdf = require('node-qpdf');

var options = {
    keyLength: 128,
    password: 'YOUR_PASSWORD_TO_ENCRYPT'
}

qpdf.encrypt(localFilePath, options);

Options for Encryption

The following are required options

  • keyLength: - a number which defines the encryption algorithm to be used. Values can be 40, 128 and 256 only.
  • password: - a string containing the secret password which will be further used to unlock the PDF.

You might want to set other options for each encryption algorithm inside restrictions: JSON according to the keyLength you choose :-

Key Length: 40

| Option | Value | Description | |:---|:---|:---| print: | 'y', 'n' | Determines whether or not to allow printing. modify: | 'y', 'n' | Determines whether or not to allow document modification. extract: | 'y', 'n' | Determines whether or not to allow text/image extraction. annotate: | 'y', 'n' | Determines whether or not to allow comments and form fill-in and signing.

Key Length: 128

| Option | Value | Description | |:---|:---|:---| print: | 'full', 'low', 'none' | full: allow full printing. low: allow low-resolution printing only. none: disallow printing. modify: | 'all', 'annotate', 'form', 'assembly', 'none' | all: allow full document modification. annotate: allow comment authoring and form operations. form: allow form field fill-in and signing. assembly: allow document assembly only. none: allow no modifications. extract: | 'y', 'n' | Determines whether or not to allow text/image extraction. useAes: | 'y', 'n' | AES encryption will be used instead of RC4 encryption. accessibility: | 'y', 'n' | Determines whether or not to allow accessibility to visually impaired.

Key Length: 256

| Option | Value | Description | |:---|:---|:---| print: | 'full', 'low', 'none' | full: allow full printing. low: allow low-resolution printing only. none: disallow printing. modify: | 'all', 'annotate', 'form', 'assembly', 'none' | all: allow full document modification. annotate: allow comment authoring and form operations. form: allow form field fill-in and signing. assembly: allow document assembly only. none: allow no modifications. extract: | 'y', 'n' | Determines whether or not to allow text/image extraction. accessibility: | 'y', 'n' | Determines whether or not to allow accessibility to visually impaired.

Examples

Render and Save:

var qpdf = require('node-qpdf');

var options = {
    keyLength: 128,
    password: 'YOUR_PASSWORD_TO_ENCRYPT',
    restrictions: {
        print: 'low',
        useAes: 'y'
    }
}

qpdf.encrypt(localFilePath, options, outputFilePath);

Render and Stream:

var qpdf = require('node-qpdf');

var options = {
    keyLength: 256,
    password: 'YOUR_PASSWORD_TO_ENCRYPT',
    restrictions: {
        modify: 'none',
        extract: 'n'
    }
}

var doc = qpdf.encrypt(localFilePath, options, outputFilePath);

doc.stdout.pipe(res);

res.writeHead(200, {
    'Content-Type': 'application/pdf',
    'Access-Control-Allow-Origin': '*',
    'Content-Disposition': 'inline; filename=order.pdf'
});

Decryption

You can decrypt your PDF by following:

var qpdf = require('node-qpdf');

qpdf.decrypt(localFilePath, 'YOUR_PASSWORD_TO_DECRYPT_PDF');

Examples

Render and Save:

var qpdf = require('node-qpdf');

qpdf.decrypt(localFilePath, 'YOUR_PASSWORD_TO_DECRYPT_PDF', outputFilePath);

Render and Stream:

var qpdf = require('node-qpdf');

var doc = qpdf.decrypt(localFilePath, 'YOUR_PASSWORD_TO_DECRYPT_PDF', outputFilePath);

doc.stdout.pipe(res);

res.writeHead(200, {
    'Content-Type': 'application/pdf',
    'Access-Control-Allow-Origin': '*',
    'Content-Disposition': 'inline; filename=order.pdf'
});

Meta

Maintained by Nishit Hirani

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/nrhirani/node-qpdf.

License

The npm package is available as open source under the terms of the MIT License.