{"_id":"@jsreport/node-signpdf","_rev":"3-8dc653d4e49a93221afa4c08ac514c98","name":"@jsreport/node-signpdf","dist-tags":{"latest":"1.4.3"},"versions":{"1.4.2":{"name":"@jsreport/node-signpdf","version":"1.4.2","keywords":["sign","verify","pdf","node","nodejs","esign","adobe","ppklite","sign detached","pkcs7","pkcs#7","pades","digital signature"],"license":"MIT","_id":"@jsreport/node-signpdf@1.4.2","maintainers":[{"name":"pofider","email":"jan.blaha@hotmail.com"},{"name":"bjrmatos","email":"bjrmatos@gmail.com"}],"homepage":"https://github.com/vbuch/node-signpdf#readme","bugs":{"url":"https://github.com/vbuch/node-signpdf/issues"},"dist":{"shasum":"982ba2cdb1571b5eb75c8ec473d9563a657f42b4","tarball":"https://registry.npmjs.org/@jsreport/node-signpdf/-/node-signpdf-1.4.2.tgz","fileCount":93,"integrity":"sha512-qk2IBd27OcrUc0JTNgzTwErZtOWO1BRzMEp153ShtZv9HGRF5KiyhAR0PqBx32LKdwlzcaCwHzSC9ciiuZJC/g==","signatures":[{"sig":"MEUCIQCm1JehSbtnJZnglutdCLGYGwbc1me9E85YYaa9EKIsUQIgItqW8xOAnHzwf10vJaOFXcKW27SQz7Ae3FjiwKrJOsc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":432111,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh8dSsCRA9TVsSAnZWagAAKesP/RWHUx3ucFMBhUukBdcQ\nYfEUeaDNiFoVWvQi11SOQpdNjD2tTlwl7roIzBMzECML7hhbaCjd7h/cyhW1\n7WyQUoN1qaLPIHt5fCRB2n0bhMM9MmDFul18lRgTZbg9WO8hzvkoIRvIdhFT\nGRJ0d4Tp6u0o/mcZrx8/VHwPWPi5nOafYm10OS30YJ/OGrOPQhqBEg9JbUGm\nWETBlhgi10rYXJzb/Iu/6YaYkTXSE3e5imlZbL6lfsoVk65miBn6XnrINZUs\nTgiIdoynp6NmYTjnM5+jKGvF/0Jq+2Zkb1TCzKFd0jwwFSAmCAcRlK+Z5CqN\nhKBe4whzJIqq0d+xu2cTACqnpLn4sGiaFD9MwIjyttfN+ACH1SE7vVOjPAW2\nV9l2Ri1HJevp3Y+VZTwTX85528RkofokPH7e11GEag/JEVm1Wg1oKFAikXxj\nQuTvyCxQyaHGwxC2txnxjnd1SzM+1I64TwpgX1ycEAGRV87zm88vW5V3Zsxs\nlpgcYd9wlLdKbvmIJk+LUcfc9ymACWdJZIaY37og4i49PCF8zEVNiex5b/U/\nUxe5sHS1K/sGgi9VzPB7UFGMH7+N8ePK8oTs7C8lojdsrNV8fu8k4xhBHSZw\nts1IWODCNnwCJlsd/x1H8sbjdOX//GreAFcPl4/r66GbbkaT5tDAjEaVL4vG\nBV5E\r\n=FYnc\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/signpdf.js","engines":{"node":">=8.9"},"gitHead":"3f341a6282b932617c813e44f1f6ce1f5c617c7c","scripts":{"lint":"eslint -c .eslintrc --ignore-path .eslintignore ./","test":"jest","build":"babel ./src -d ./dist --ignore \"**/*.test.js\"","prepush":"npm run test","precommit":"npm run lint","test:watch":"jest --watch","build:watch":"babel --watch ./src -d ./dist --ignore \"**/*.test.js\"","test:coverage":"jest --coverage"},"_npmUser":{"name":"pofider","email":"jan.blaha@hotmail.com"},"repository":{"url":"git+https://github.com/vbuch/node-signpdf.git","type":"git"},"_npmVersion":"8.1.2","description":"Simple signing of PDFs in node.","directories":{},"_nodeVersion":"16.13.2","_hasShrinkwrap":false,"devDependencies":{"jest":"^27.3.1","eslint":"^8.2.0","pdfkit":"^0.10.0","coveralls":"^3.0.2","@babel/cli":"^7.0.0","babel-jest":"^27.3.1","node-forge":"1.2.1","@babel/core":"^7.4.0","@babel/node":"^7.0.0","babel-eslint":"^10.1.0","assertion-error":"^1.1.0","@babel/preset-env":"^7.4.2","eslint-plugin-jest":"^25.2.4","@babel/eslint-parser":"^7.16.3","eslint-plugin-import":"^2.25.3","eslint-config-airbnb-base":"^15.0.0","babel-plugin-module-resolver":"^3.1.1","eslint-import-resolver-babel-module":"^5.3.1","@babel/plugin-syntax-object-rest-spread":"^7.0.0"},"peerDependencies":{"node-forge":">=1.2.1"},"_npmOperationalInternal":{"tmp":"tmp/node-signpdf_1.4.2_1643238571887_0.6121027021970065","host":"s3://npm-registry-packages"}},"1.4.3":{"name":"@jsreport/node-signpdf","version":"1.4.3","description":"Simple signing of PDFs in node.","repository":{"type":"git","url":"git+https://github.com/vbuch/node-signpdf.git"},"license":"MIT","keywords":["sign","verify","pdf","node","nodejs","esign","adobe","ppklite","sign detached","pkcs7","pkcs#7","pades","digital signature"],"main":"dist/signpdf.js","engines":{"node":">=8.9"},"scripts":{"test:coverage":"jest --coverage","test":"jest","test:watch":"jest --watch","build":"babel ./src -d ./dist --ignore \"**/*.test.js\"","build:watch":"babel --watch ./src -d ./dist --ignore \"**/*.test.js\"","lint":"eslint -c .eslintrc --ignore-path .eslintignore ./","precommit":"npm run lint","prepush":"npm run test"},"peerDependencies":{"node-forge":">=1.3.3"},"devDependencies":{"@babel/cli":"^7.0.0","@babel/core":"^7.4.0","@babel/eslint-parser":"^7.16.3","@babel/node":"^7.0.0","@babel/plugin-syntax-object-rest-spread":"^7.0.0","@babel/preset-env":"^7.4.2","assertion-error":"^1.1.0","babel-eslint":"^10.1.0","babel-jest":"^27.3.1","babel-plugin-module-resolver":"^3.1.1","coveralls":"^3.0.2","eslint":"^8.2.0","eslint-config-airbnb-base":"^15.0.0","eslint-import-resolver-babel-module":"^5.3.1","eslint-plugin-import":"^2.25.3","eslint-plugin-jest":"^25.2.4","jest":"^27.3.1","node-forge":"1.3.3","pdfkit":"^0.10.0"},"_id":"@jsreport/node-signpdf@1.4.3","gitHead":"e9a3b8151ae3c24b8d267cc4e449b26439161505","bugs":{"url":"https://github.com/vbuch/node-signpdf/issues"},"homepage":"https://github.com/vbuch/node-signpdf#readme","_nodeVersion":"22.21.1","_npmVersion":"10.9.4","dist":{"integrity":"sha512-Bo+lXzRbNxX6RBq1Pf/uXE2IA0mhyA0pWULre96XVrrc8MSBQsc8EmK+Edrd8oZ+ulRdym5DL/bxt5T3hwQJcg==","shasum":"1e33153ac03c18c4664413e973410adc90895d03","tarball":"https://registry.npmjs.org/@jsreport/node-signpdf/-/node-signpdf-1.4.3.tgz","fileCount":93,"unpackedSize":428222,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIGh2BTQ2i9YkgJJMFAZ5KIWRde73yEpz8X8XQbLNJXM4AiEA1gcFqH19spS4MnkatahLNhsVqQQg1kG7nBtivkih1e4="}]},"_npmUser":{"name":"pofider","email":"jan.blaha@hotmail.com"},"directories":{},"maintainers":[{"name":"pofider","email":"jan.blaha@hotmail.com"},{"name":"bjrmatos","email":"bjrmatos@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/node-signpdf_1.4.3_1765221621074_0.15493902874686882"},"_hasShrinkwrap":false}},"time":{"created":"2022-01-26T23:09:31.843Z","modified":"2025-12-08T19:20:21.475Z","1.4.2":"2022-01-26T23:09:32.096Z","1.4.3":"2025-12-08T19:20:21.231Z"},"bugs":{"url":"https://github.com/vbuch/node-signpdf/issues"},"license":"MIT","homepage":"https://github.com/vbuch/node-signpdf#readme","keywords":["sign","verify","pdf","node","nodejs","esign","adobe","ppklite","sign detached","pkcs7","pkcs#7","pades","digital signature"],"repository":{"type":"git","url":"git+https://github.com/vbuch/node-signpdf.git"},"description":"Simple signing of PDFs in node.","maintainers":[{"name":"pofider","email":"jan.blaha@hotmail.com"},{"name":"bjrmatos","email":"bjrmatos@gmail.com"}],"readme":"# ![node-signpdf](https://raw.githubusercontent.com/vbuch/node-signpdf/master/resources/logo-horizontal.svg?sanitize=true)\n\n[![npm version](https://badge.fury.io/js/node-signpdf.svg)](https://badge.fury.io/js/node-signpdf)\n[![Build Status](https://travis-ci.com/vbuch/node-signpdf.svg?branch=master)](https://travis-ci.com/vbuch/node-signpdf)\n[![Coverage Status](https://coveralls.io/repos/github/vbuch/node-signpdf/badge.svg?branch=master)](https://coveralls.io/github/vbuch/node-signpdf?branch=master)\n[![Known Vulnerabilities](https://snyk.io/test/npm/node-signpdf/badge.svg)](https://snyk.io/test/npm/node-signpdf)\n\nSimple signing of PDFs in node.\n\n* [node-signpdf](#node-signpdf)\n  * [Purpose](#purpose)\n  * [Usage](#usage)\n  * [Notes](#notes)\n  * [Signing PDF in simple steps](#signing-pdf-in-simple-steps)\n    * [Generate a PDF](#generate-a-pdf)\n    * [Append a signature placeholder](#append-a-signature-placeholder)\n    * [Generate and apply signature](#generate-and-apply-signature)\n  * [Dependencies](#dependencies)\n  * [Credits](#credits)\n  * [Contributing](#contributing)\n\n## Purpose\n\nThe purpose of this package is not as much to be used as a dependendency, although it could. The main purpose is **to demonstrate** the way signing can be achieved **in a piece of readable code** as it can take a lot of hours to figure out.\n\n## Usage\n\nInstall with  `npm i -S node-signpdf node-forge`.\n\nIn practice we expect that most people will just read through the code we've written in the testing part of this package and figure it out themselves. If that's your case, you should read the [[Signing PDF in simple steps]](#signing-pdf-in-simple-steps) section.\n\n### With pdfkit-created document\n\nYou have already created a PDF using foliojs/pdfkit and you want to sign that. Before saving (writing to fs, or just converting to `Buffer`) your file, you need to a add a signature placeholder to it. We have a helper for that. This is demonstrated in [the `signs input PDF` test](./src/signpdf.test.js#L111).\n\nOnce you have the placeholder, just [[sign the document]](#sign-the-document).\n\n### With any PDF document\n\nYes. This is new since version 1.0. We have a helper that can add a signature placeholder in at least the most basic PDFs without depending on pdfkit. You can see how this is done in [the `signs a ready pdf` test](./src/signpdf.test.js#L136).\n\nOnce you have the placeholder, just [[sign the document]](#sign-the-document).\n\n### Sign the document\n\n```javascript\nimport signer from 'node-signpdf';\n...\nconst signedPdf = signer.sign(\n  fs.readFileSync(PATH_TO_PDF_FILE),\n  fs.readFileSync(PATH_TO_P12_CERTIFICATE),\n);\n```\n\n## Notes\n\n* The process of signing a document is described in the [Digital Signatures in PDF](https://www.adobe.com/devnet-docs/etk_deprecated/tools/DigSig/Acrobat_DigitalSignatures_in_PDF.pdf) document. As Adobe's files are deprecated, [here is the standard as defined by ETSI](https://ec.europa.eu/cefdigital/wiki/display/CEFDIGITAL/eSignature+standards#eSignaturestandards-PAdES%28PDFAdvancedElectronicSignature%29BaselineProfile).\n* This lib:\n  * requires the [signature placeholder](#append-a-signature-placeholder) to already be in the document (There are helpers included that can try to add it);\n  * requires the `Contents` descriptor in the `Sig` be placed after the `ByteRange` one;\n  * takes `Buffer`s of the PDF and a P12 certificate to use when [signing](#generate-and-apply-signature);\n  * does cover only basic scenarios of signing a PDF. If you have suggestions, ideas or anything, please [CONTRIBUTE](#contributing);\n* Feel free to copy and paste any part of this code. See its defined [Purpose](#purpose).\n\n## Signing PDF in simple steps\n\n### Generate a PDF\n\nSee the [unit-testing code](https://github.com/vbuch/node-signpdf/blob/master/src/signpdf.test.js). PDFKit is used there for generating the document. This also allows easy addition of the signature placeholder.\n\n### Append a signature placeholder\n\nWhat's needed is a `Sig` element and a `Widget` that is also linked in a `Form`. The form needs to be referenced in the root descriptor of the PDF as well. A (hopefully) [readable sample](https://github.com/vbuch/node-signpdf/blob/master/src/helpers/pdfkitAddPlaceholder.js) is available in the helpers. Note the `Contents` descriptor of the `Sig` where zeros are placed that will later be replaced with the actual signature.\n\nThis package provides two [helpers](https://github.com/vbuch/node-signpdf/blob/master/src/helpers/index.js) for adding the signature placeholder:\n\n* pdfkitAddPlaceholder\n* plainAddPlaceholder\n\n**Note:** Signing in detached mode makes the signature length independent of the PDF's content length, but it may still vary between different signing certificates. So every time you sign using the same P12 you will get the same length of the output signature, no matter the length of the signed content. It is safe to find out the actual signature length your certificate produces and use it to properly configure the placeholder length.\n\n#### PAdES compliant signatures\n\nTo produce PAdES compliant signatures, the ETSI Signature Dictionary SubFilter value must be `ETSI.CAdES.detached` instead of the standard Adobe value.\n\nThis can be declared using the subFilter option argument passed to `pdfkitAddPlaceholder` and `plainAddPlaceholder`.\n\n```js\nimport { SUBFILTER_ETSI_CADES_DETACHED, pdfkitAddPlaceholder } from 'node-signpdf';\n\nconst pdfToSign = pdfkitAddPlaceholder({\n  ...,\n  subFilter: SUBFILTER_ETSI_CADES_DETACHED,\n});\n```\n\n### Generate and apply signature\n\nThat's where the Signer kicks in. Given a PDF and a P12 certificate a signature is generated in detached mode and is replaced in the placeholder. This is best demonstrated in [the tests](https://github.com/vbuch/node-signpdf/blob/master/src/signpdf.test.js#L100).\n\n## Dependencies\n\n[node-forge](https://github.com/digitalbazaar/forge) is used for working with signatures.\n\n[PDFKit](https://github.com/foliojs/pdfkit) is used in the tests for generating a PDF with a signature placeholder.\n\n## Credits\n\n* The whole signing flow is a rework of what's already [in pdfsign.js](https://github.com/Communication-Systems-Group/pdfsign.js/blob/master/src/js/main.js#L594) so thanks go to [@tbocek](https://github.com/tbocek)\n* [node-forge](https://github.com/digitalbazaar/forge) is an awesome package written in pure JavaScript and [supports signing in detached mode](https://github.com/digitalbazaar/forge/pull/605). Many thanks to all the guys who wrote and maintain it.\n* Thanks to the guys of [PDFKit](https://github.com/foliojs/pdfkit) as well. They've made PDF generation incredibly easy.\n\n## [Contributing](CONTRIBUTING.md)\n\n## [Changelog](CHANGELOG.md)\n","readmeFilename":"README.md"}