{"_id":"node-qpdf","_rev":"8-607482b80247dbb4407493adcd73ac55","name":"node-qpdf","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0":{"name":"node-qpdf","version":"1.0.0","keywords":["pdf","password protect","encrypt","dcrypt","aes","rc4","aes-256","aes-128","rc4-128","rc4-40"],"author":{"name":"Nishit Hirani","email":"nrhirani@gmail.com"},"license":"MIT","_id":"node-qpdf@1.0.0","maintainers":[{"name":"nrhirani","email":"nrhirani@gmail.com"}],"homepage":"https://github.com/nrhirani/node-qpdf#node-qpdf","bugs":{"url":"https://github.com/nrhirani/node-qpdf/issues"},"dist":{"shasum":"1c1ae79911a6e5ce9d6f8218b88b9ce4f7d2d5fb","tarball":"https://registry.npmjs.org/node-qpdf/-/node-qpdf-1.0.0.tgz","integrity":"sha512-QiIQYAH0YYBlRG75kAh9uMFVoGeoZ0NGB5pIzmSNBX1sWOe5JlTKBTLtrkoneU7FD0RFjByjaTrIDkFCSib+pg==","signatures":[{"sig":"MEQCIGUDisf9HnBUmfOYo7XEDkf5XiYF3WjMMEUXg3cLOJi/AiAtjR2+z9vrR9sr0gx+sGqswP7iIvJZb0NY3yVlAI7A0A==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","_shasum":"1c1ae79911a6e5ce9d6f8218b88b9ce4f7d2d5fb","gitHead":"5cda428e03f851c843a4e298bbd527874006dca0","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"nrhirani","email":"nrhirani@gmail.com"},"repository":{"url":"git+https://github.com/nrhirani/node-qpdf.git","type":"git"},"_npmVersion":"3.8.8","description":"A Content Preserving transformations on PDFs wrapped around QPDF","_nodeVersion":"0.10.26","_npmOperationalInternal":{"tmp":"tmp/node-qpdf-1.0.0.tgz_1462103209333_0.34468143503181636","host":"packages-12-west.internal.npmjs.com"},"directories":{}},"1.0.1":{"name":"node-qpdf","version":"1.0.1","keywords":["pdf","qpdf","password protect","password protect pdf","pdf encryption","pdf decryption","encrypt","dcrypt","aes","rc4","aes-256","aes-128","rc4-128","rc4-40"],"author":{"name":"Nishit Hirani","email":"nrhirani@gmail.com"},"license":"MIT","_id":"node-qpdf@1.0.1","maintainers":[{"name":"nrhirani","email":"nrhirani@gmail.com"}],"homepage":"https://github.com/nrhirani/node-qpdf#node-qpdf","bugs":{"url":"https://github.com/nrhirani/node-qpdf/issues"},"dist":{"shasum":"3d0b48e2f0714aa7d9c78ec08e3a948e6ff228b2","tarball":"https://registry.npmjs.org/node-qpdf/-/node-qpdf-1.0.1.tgz","integrity":"sha512-E1nM0sXxRvgoIodXcf7OAYYPtcLMr3eOpd5JrfYYdOVVF5NwCTHL1th2kCRaQJyS5AdgAr1QuiC9L+5HGxXAFg==","signatures":[{"sig":"MEUCIAl9WvR53A3qSH4WCM/MaKgwcKd+f3nXo/0Qv4VZdeEkAiEA9RU32WwGdvPSqpTZ9qZ4NPQtMmh8m6RZpQj7wSuuiOE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","_shasum":"3d0b48e2f0714aa7d9c78ec08e3a948e6ff228b2","gitHead":"c62739d00bf74fdd15e91db216ca6a8edf335ac5","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"nrhirani","email":"nrhirani@gmail.com"},"repository":{"url":"git+https://github.com/nrhirani/node-qpdf.git","type":"git"},"_npmVersion":"3.8.8","description":"A Content Preserving transformations on PDFs wrapped around QPDF","_nodeVersion":"0.10.26","_npmOperationalInternal":{"tmp":"tmp/node-qpdf-1.0.1.tgz_1462104294272_0.3722722365055233","host":"packages-12-west.internal.npmjs.com"},"directories":{}},"1.0.2":{"name":"node-qpdf","version":"1.0.2","keywords":["pdf","qpdf","password protect","password protect pdf","pdf encryption","pdf decryption","encrypt","dcrypt","aes","rc4","aes-256","aes-128","rc4-128","rc4-40"],"author":{"name":"Nishit Hirani","email":"nrhirani@gmail.com"},"license":"MIT","_id":"node-qpdf@1.0.2","maintainers":[{"name":"nrhirani","email":"nrhirani@gmail.com"}],"homepage":"https://github.com/nrhirani/node-qpdf#node-qpdf","bugs":{"url":"https://github.com/nrhirani/node-qpdf/issues"},"dist":{"shasum":"bae66b152fd8a6a6b48f6c97298b78e14b0913a0","tarball":"https://registry.npmjs.org/node-qpdf/-/node-qpdf-1.0.2.tgz","integrity":"sha512-Fwe5EWM5C+M6Lq4he2KyfuFJawLsE2qc9Ywo9qIF/hg2i0pYxhQVsfwq5JXR0FrXFH2Re4YIouehnq6To2H9YQ==","signatures":[{"sig":"MEUCIQD2Kwj4odn46UHRYpDSpYUiFmE4bpbRv5yMCpC6oXISNQIgD1Bdoojbyk7Xte5sjcEzCD8XEr3I9/dRZSlBNYhwoqo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","_shasum":"bae66b152fd8a6a6b48f6c97298b78e14b0913a0","gitHead":"e63900a43dbfed1fa6ee3474c8ee2cf48692234a","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"nrhirani","email":"nrhirani@gmail.com"},"repository":{"url":"git+https://github.com/nrhirani/node-qpdf.git","type":"git"},"_npmVersion":"3.8.8","description":"A Content Preserving transformations on PDFs wrapped around QPDF","_nodeVersion":"0.10.26","_npmOperationalInternal":{"tmp":"tmp/node-qpdf-1.0.2.tgz_1466921292077_0.7910449616611004","host":"packages-16-east.internal.npmjs.com"},"directories":{}},"1.0.3":{"name":"node-qpdf","version":"1.0.3","keywords":["pdf","qpdf","password protect","password protect pdf","pdf encryption","pdf decryption","encrypt","dcrypt","aes","rc4","aes-256","aes-128","rc4-128","rc4-40"],"author":{"name":"Nishit Hirani","email":"nrhirani@gmail.com"},"license":"MIT","_id":"node-qpdf@1.0.3","maintainers":[{"name":"nrhirani","email":"nrhirani@gmail.com"}],"homepage":"https://github.com/nrhirani/node-qpdf#node-qpdf","bugs":{"url":"https://github.com/nrhirani/node-qpdf/issues"},"dist":{"shasum":"29cdb3ff58f67aa14664afcfa59c44097fa677e2","tarball":"https://registry.npmjs.org/node-qpdf/-/node-qpdf-1.0.3.tgz","integrity":"sha512-M1Y5+7Ycm93Uwd7MhLUVTzRUTgHGiPiqjdYqNYoma9WGuiVvzwQ8EeyBKKwVbu3fK83lDxUBf+GX8G0S9Nx8ew==","signatures":[{"sig":"MEYCIQC3HJG5NNfaleLVaZENlpZvkuFM0Ol3h2DtRME4kScY8gIhAJXlsvcD/sxiw1cBDJzY/LvjyzxYG65hXCJ4VnZYm/EG","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","_shasum":"29cdb3ff58f67aa14664afcfa59c44097fa677e2","gitHead":"db38d13c761506b7baa5262ed555a8bdee554888","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"nrhirani","email":"nrhirani@gmail.com"},"repository":{"url":"git+https://github.com/nrhirani/node-qpdf.git","type":"git"},"_npmVersion":"3.10.9","description":"A Content Preserving transformations on PDFs wrapped around QPDF","_nodeVersion":"7.1.0","_npmOperationalInternal":{"tmp":"tmp/node-qpdf-1.0.3.tgz_1516706555048_0.27442331914789975","host":"s3://npm-registry-packages"},"directories":{}},"2.0.0":{"_id":"node-qpdf@2.0.0","bugs":{"url":"https://github.com/nrhirani/node-qpdf/issues"},"dist":{"shasum":"3c12f408c450210eb0e8bd37f28c5ee39f1702ac","tarball":"https://registry.npmjs.org/node-qpdf/-/node-qpdf-2.0.0.tgz","fileCount":5,"integrity":"sha512-mSkF8I4RZuDglhaCYBQspHFoyTQdWOcOj54cZCZQM3fdQilweN+yngdSrBSiO+9ewyMnB8eCqJqgzJ0lABwNjg==","signatures":[{"sig":"MEUCIQDon2WLlDi0xCslTxayW4hbfUJpKyJvPCl/BCuMoWBVpwIgAmZ8UfhC1JHxVBLfSajVK240TuNMhcDdfUY5TXeUSiQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDChRzo3Fud+NoyfPpmxhKWs2tn+0MM8K95u24deCnnQQIhAPqIK2lvHCJDRj0btjQM+jPnNMjCEcCO12FQDnky0avt"}],"unpackedSize":31636},"main":"index.js","name":"node-qpdf","author":{"name":"Nishit Hirani","email":"nrhirani@gmail.com"},"engines":{"node":">=8.0.0"},"gitHead":"8758009ca0f17345f466ac55be9a0e83a51fa491","license":"MIT","scripts":{"test":"node --test test/validation.test.js test/process.test.js test/qpdf.test.js"},"version":"2.0.0","_npmUser":{"name":"nrhirani","email":"nrhirani@gmail.com"},"homepage":"https://github.com/nrhirani/node-qpdf#node-qpdf","keywords":["pdf","qpdf","password protect","password protect pdf","pdf encryption","pdf decryption","encrypt","decrypt","aes","rc4","aes-256","aes-128","rc4-128","rc4-40"],"repository":{"url":"git+https://github.com/nrhirani/node-qpdf.git","type":"git"},"_npmVersion":"11.19.1","description":"Encrypt and decrypt PDF files with qpdf (AES-256, AES-128)","directories":{},"maintainers":[{"name":"nrhirani","email":"nrhirani@gmail.com"}],"_nodeVersion":"24.22.2","_hasShrinkwrap":false,"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/node-qpdf_2.0.0_1793870674435_0.6440926002927776"}}},"time":{"created":"2016-05-01T11:46:49.726Z","modified":"2026-11-05T09:24:34.665Z","1.0.0":"2016-05-01T11:46:49.726Z","1.0.1":"2016-05-01T12:04:54.664Z","1.0.2":"2016-06-26T06:08:15.850Z","1.0.3":"2018-01-23T11:22:36.908Z","2.0.0":"2026-11-05T09:24:34.519Z"},"bugs":{"url":"https://github.com/nrhirani/node-qpdf/issues"},"author":{"name":"Nishit Hirani","email":"nrhirani@gmail.com"},"license":"MIT","homepage":"https://github.com/nrhirani/node-qpdf#node-qpdf","keywords":["pdf","qpdf","password protect","password protect pdf","pdf encryption","pdf decryption","encrypt","decrypt","aes","rc4","aes-256","aes-128","rc4-128","rc4-40"],"repository":{"url":"git+https://github.com/nrhirani/node-qpdf.git","type":"git"},"description":"Encrypt and decrypt PDF files with qpdf (AES-256, AES-128)","maintainers":[{"name":"nrhirani","email":"nrhirani@gmail.com"}],"readme":"# node-qpdf\n[![npm version](https://badge.fury.io/js/node-qpdf.svg)](https://badge.fury.io/js/node-qpdf) [![NPM Downloads](https://img.shields.io/npm/dt/node-qpdf.svg)](https://www.npmjs.com/package/node-qpdf) [![NPM Downloads](https://img.shields.io/npm/dm/node-qpdf.svg)](https://www.npmjs.com/package/node-qpdf)\n\nA small Node.js wrapper around [qpdf](https://github.com/qpdf/qpdf) for encrypting and decrypting PDF files with AES-256 (default), AES-128 and, if you explicitly allow it, the legacy RC4 algorithms.\n\n> **Upgrading from 1.x?** Version 2.0.0 has breaking changes. See [CHANGELOG.md](CHANGELOG.md#200) for what changed and how to migrate.\n\n## Requirements\n* [Node.js](https://nodejs.org/) 8 or newer (running the test suite needs Node.js 18 or newer)\n  * The stream examples below use `stream.pipeline()`, which needs Node.js 10 or newer. On Node.js 8, use `.pipe()` and listen for `'error'` on the stream returned by node-qpdf.\n* [qpdf](https://github.com/qpdf/qpdf) **7.0 or newer**. node-qpdf passes passwords to qpdf through standard input, which older versions do not support.\n  * `allowWeakCrypto` (see [Weak encryption](#weak-encryption)) needs qpdf 10.4 or newer.\n\n## Installation\n1. Install qpdf:\n    * With a package manager, e.g. `apt install qpdf`, `brew install qpdf` or `choco install qpdf`\n    * Or download a release from [GitHub](https://github.com/qpdf/qpdf/releases); see the [qpdf manual](https://qpdf.readthedocs.io/) for details.\n    * Check the version with `qpdf --version`.\n2. Install node-qpdf:\n    ```\n    npm install node-qpdf\n    ```\n\nIf qpdf is not on your `PATH`, point node-qpdf at it:\n```js\nqpdf.command = '/opt/qpdf/bin/qpdf';\n```\n\n## Quick start\nThe examples use `await`, so run them inside an `async` function (or an ES module).\n\n```js\nconst qpdf = require('node-qpdf');\n\n// Encrypt to a file (AES-256)\nawait qpdf.encrypt('report.pdf', {\n  password: 'secret',\n  outputFile: 'report-protected.pdf'\n});\n\n// Decrypt to a file\nawait qpdf.decrypt('report-protected.pdf', {\n  password: 'secret',\n  outputFile: 'report-unlocked.pdf'\n});\n```\n\n## How results are delivered\n`encrypt()` and `decrypt()` work the same way:\n\n| | With `outputFile` | Without `outputFile` |\n|:---|:---|:---|\n| **No callback** | Returns a Promise that resolves with the output path | Returns a readable stream of the PDF |\n| **With callback** | Calls `callback(err, outputFile)` when qpdf finishes | Returns the stream **and** calls `callback(null, stream)` right away |\n\nIn stream mode, errors from qpdf (wrong password, damaged file, ...) are emitted as `'error'` on the stream, and the stream ends normally only if qpdf succeeds. **Always handle `'error'` on the stream**, for example with `stream.pipeline()`, or an error will crash your process.\n\nInvalid arguments are reported the same way: through the callback, as a rejected Promise, or as an `'error'` on the returned stream.\n\n## Encryption\n```js\nqpdf.encrypt(input, options, [callback])\n```\n\n| Option | Type | Description |\n|:---|:---|:---|\n| `password` | string or `{ user, owner }` | **Required.** See [Passwords](#passwords). |\n| `keyLength` | `256` (default), `128` or `40` | Encryption strength. 128-bit uses AES unless `restrictions.useAes` is `false`. |\n| `restrictions` | object | Permissions to restrict. See [Restrictions](#restrictions). |\n| `outputFile` | string | Where to write the encrypted PDF. Leave it out to get a stream. Must differ from `input`. |\n| `allowWeakCrypto` | boolean | Allow 40-bit or 128-bit RC4 encryption. See [Weak encryption](#weak-encryption). |\n| `onWarning` | function | Called with qpdf's warning text when qpdf succeeds with warnings. See [Warnings](#warnings). |\n\n### Passwords\n* **A single string**, e.g. `password: 'secret'`, sets the *user* password, which is needed to open the file. The *owner* password, which allows changing permissions, is set to a strong random value that is never revealed. This makes the restrictions actually enforceable: someone who only knows the user password cannot remove them.\n* **`{ user, owner }`** sets both passwords yourself. `user` may be `''`, so anyone can open the file but only the owner can change its permissions. `owner` must not be empty.\n\nPasswords (and file paths) must not contain line breaks, and encryption passwords must not start with `-`.\n\n### Restrictions\nValues are strings as listed below; options that take `'y'`/`'n'` also accept `true`/`false`. Options listed without values are switches: set them to `true` to turn them on.\n\n**256-bit and 128-bit**\n\n| Option | Values | Description |\n|:---|:---|:---|\n| `print` | `'full'`, `'low'`, `'none'` | Allow full printing, low-resolution printing only, or no printing. |\n| `modify` | `'all'`, `'annotate'`, `'form'`, `'assembly'`, `'none'` | Modification level. `annotate`: comments and forms; `form`: filling in forms and signing; `assembly`: document assembly only. |\n| `extract` | `'y'`, `'n'` | Allow text and graphics extraction. |\n| `accessibility` | `'y'`, `'n'` | Allow extraction for accessibility (usually ignored by readers). |\n| `annotate` | `'y'`, `'n'` | Allow commenting and filling in form fields. |\n| `assemble` | `'y'`, `'n'` | Allow document assembly. |\n| `form` | `'y'`, `'n'` | Allow filling in form fields. |\n| `modifyOther` | `'y'`, `'n'` | Allow other modifications. |\n| `cleartextMetadata` | switch | Leave the document metadata unencrypted. |\n\n**128-bit only:** `useAes` (`'y'`, `'n'`; defaults to `'y'`) and `forceV4` (switch).\n**256-bit only:** `forceR5` (switch; uses a deprecated encryption variant).\n\n**40-bit:** `print`, `modify`, `extract` and `annotate`, each `'y'` or `'n'`.\n\nUnknown options, and options that do not apply to the chosen `keyLength`, are rejected. Not all PDF readers respect all restrictions.\n\n### Weak encryption\n40-bit encryption and 128-bit RC4 (`keyLength: 128` with `useAes: false`) are insecure, and qpdf 11 and newer refuse to create them by default. node-qpdf rejects them unless you set `allowWeakCrypto: true`, which needs qpdf 10.4 or newer:\n\n```js\nqpdf.encrypt('in.pdf', {\n  password: 'secret',\n  keyLength: 40,\n  allowWeakCrypto: true,   // only if you really need compatibility with very old readers\n  outputFile: 'out.pdf'\n});\n```\n\n### Examples\nEncrypt to a file with restrictions, using a callback:\n```js\nqpdf.encrypt('in.pdf', {\n  password: { user: 'reader-password', owner: 'owner-password' },\n  restrictions: { print: 'low', modify: 'none', extract: false },\n  outputFile: 'out.pdf'\n}, (err, outputFile) => {\n  if (err) return console.error(err);\n  console.log('Written to', outputFile);\n});\n```\n\nEncrypt and send the result as an HTTP response (Express):\n```js\nconst { pipeline } = require('stream');\n\napp.get('/report.pdf', (req, res) => {\n  res.type('application/pdf');\n  pipeline(qpdf.encrypt('report.pdf', { password: 'secret' }), res, (err) => {\n    if (err) console.error('Encryption failed:', err.message);\n  });\n});\n```\n\n## Decryption\n```js\nqpdf.decrypt(input, password, [callback])\nqpdf.decrypt(input, options, [callback])\n```\n\n`password` is a string. Use `''` for files protected only by an owner password. Or pass an options object:\n\n| Option | Type | Description |\n|:---|:---|:---|\n| `password` | string | **Required.** May be `''`. |\n| `outputFile` | string | Where to write the decrypted PDF. Leave it out to get a stream. Must differ from `input`. |\n| `onWarning` | function | Called with qpdf's warning text when qpdf succeeds with warnings. |\n\nResults are delivered as described in [How results are delivered](#how-results-are-delivered).\n\n### Examples\nDecrypt to a file:\n```js\nawait qpdf.decrypt('protected.pdf', { password: 'secret', outputFile: 'unlocked.pdf' });\n```\n\nDecrypt to a stream:\n```js\nconst fs = require('fs');\nconst { pipeline } = require('stream');\n\npipeline(qpdf.decrypt('protected.pdf', 'secret'), fs.createWriteStream('unlocked.pdf'), (err) => {\n  if (err) console.error('Decryption failed:', err.message);\n});\n```\n\n## Warnings\nqpdf can succeed with warnings, for example after repairing a damaged file. The result is still delivered normally; to see the warnings, pass `onWarning`:\n\n```js\nawait qpdf.decrypt('scanned.pdf', {\n  password: 'secret',\n  outputFile: 'unlocked.pdf',\n  onWarning: (message) => console.warn(message)\n});\n```\n\n## Errors\nErrors from qpdf have these properties:\n\n| Property | Description |\n|:---|:---|\n| `message` | qpdf's error output, e.g. `qpdf: in.pdf: invalid password` |\n| `code` | qpdf's exit code (usually `2`), or `'ENOENT'` if qpdf could not be found |\n| `signal` | The signal that stopped qpdf, if any |\n| `stderr` | Everything qpdf wrote to its error output |\n\n## Security notes\n* Passwords are never put on qpdf's command line, where other users of the machine could see them (for example with `ps`). They are passed to qpdf through a pipe on standard input and are never written to disk.\n* qpdf is started directly, without a shell, so passwords and file names are never interpreted as shell commands.\n\n## Running the tests\n```\nnpm test\n```\nThe tests use Node.js's built-in test runner (Node.js 18 or newer). Tests that need a real qpdf use `qpdf` from your `PATH`, or the binary named in `QPDF_BIN`, and are skipped if it is not found:\n```\nQPDF_BIN=/path/to/qpdf npm test\n```\n\n## Meta\n\nMaintained by [Nishit Hirani](http://www.twitter.com/nrhirani)\n\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/nrhirani/node-qpdf.\n\n\n## License\n\nThe npm package is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","readmeFilename":"README.md"}