All Projects β†’ vbuch β†’ Node Signpdf

vbuch / Node Signpdf

Licence: mit
Simple signing of PDFs in node.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Signpdf

Fe Books
πŸ“– πŸ“– 前端书籍pdf整理
Stars: ✭ 206 (-8.85%)
Mutual labels:  pdf
Yarg
Yet Another Report Generator - CUBA Platform reporting engine
Stars: ✭ 215 (-4.87%)
Mutual labels:  pdf
Books
Awesome Books
Stars: ✭ 3,242 (+1334.51%)
Mutual labels:  pdf
Grim
Tool for extracting pages from pdf as images and text as strings.
Stars: ✭ 208 (-7.96%)
Mutual labels:  pdf
Paperwork
Personal document manager (Linux/Windows) -- Moved to Gnome's Gitlab
Stars: ✭ 2,392 (+958.41%)
Mutual labels:  pdf
Staplr
PDF Toolkit. πŸ“Ž πŸ”¨ πŸ”§ βœ‚οΈ πŸ“‘ πŸ“πŸ“Ž πŸ”– 🚧 πŸ‘·
Stars: ✭ 221 (-2.21%)
Mutual labels:  pdf
Pdfgen
Simple C PDF Writer/Generation library
Stars: ✭ 200 (-11.5%)
Mutual labels:  pdf
Mayan Edms
Free Open Source Document Management System (mirror, no pull request or issues)
Stars: ✭ 226 (+0%)
Mutual labels:  pdf
Pandoc Book Template
A simple Pandoc template to build documents and ebooks.
Stars: ✭ 214 (-5.31%)
Mutual labels:  pdf
Pdf Lib
Create and modify PDF documents in any JavaScript environment
Stars: ✭ 3,426 (+1415.93%)
Mutual labels:  pdf
Pdfium Binaries
πŸ“° Binary distribution of PDFium
Stars: ✭ 208 (-7.96%)
Mutual labels:  pdf
Adobe Scripts Panel
Scripting Panel for After Effects, Illustrator, and Photoshop
Stars: ✭ 211 (-6.64%)
Mutual labels:  adobe
Fulltext
Search across and get full text for OA & closed journals
Stars: ✭ 221 (-2.21%)
Mutual labels:  pdf
Squid
A Ruby library to plot charts in PDF files
Stars: ✭ 205 (-9.29%)
Mutual labels:  pdf
Gotenberg
A Docker-powered stateless API for PDF files.
Stars: ✭ 3,272 (+1347.79%)
Mutual labels:  pdf
Awesome Books
πŸ“š εΌ€ε‘θ€…ζŽ¨θι˜…θ―»ηš„δΉ¦η±
Stars: ✭ 2,740 (+1112.39%)
Mutual labels:  pdf
Asciidoctor Web Pdf
Convert AsciiDoc documents to PDF using web technologies
Stars: ✭ 219 (-3.1%)
Mutual labels:  pdf
Laravel Book
Up to date Epub, Mobi and PDF versions from the official Laravel Docs
Stars: ✭ 221 (-2.21%)
Mutual labels:  pdf
Best Resume Ever
πŸ‘” πŸ’Ό Build fast πŸš€ and easy multiple beautiful resumes and create your best CV ever! Made with Vue and LESS.
Stars: ✭ 15,124 (+6592.04%)
Mutual labels:  pdf
Ledgersmb
Repository for the LedgerSMB project -- web app for accounting & ERP
Stars: ✭ 222 (-1.77%)
Mutual labels:  pdf

node-signpdf

npm version Build Status Coverage Status Known Vulnerabilities

Simple signing of PDFs in node.

Purpose

The 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.

Usage

Install with npm i -S node-signpdf node-forge.

In 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] section.

With pdfkit-created document

You 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.

Once you have the placeholder, just [sign the document].

With any PDF document

Yes. 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.

Once you have the placeholder, just [sign the document].

Sign the document

import signer from 'node-signpdf';
...
const signedPdf = signer.sign(
  fs.readFileSync(PATH_TO_PDF_FILE)
  fs.readFileSync(PATH_TO_P12_CERTIFICATE),
);

Notes

  • The process of signing a document is described in the Digital Signatures in PDF document. As Adobe's files are deprecated, here is the standard as defined by ETSI.
  • This lib:
    • requires the signature placeholder to already be in the document (There are helpers included that can try to add it);
    • requires the Contents descriptor in the Sig be placed after the ByteRange one;
    • takes Buffers of the PDF and a P12 certificate to use when signing;
    • does cover only basic scenarios of signing a PDF. If you have suggestions, ideas or anything, please CONTRIBUTE;
  • Feel free to copy and paste any part of this code. See its defined Purpose.

Signing PDF in simple steps

Generate a PDF

See the unit-testing code. PDFKit is used there for generating the document. This also allows easy addition of the signature placeholder.

Append a signature placeholder

What'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 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.

This package provides two helpers for adding the signature placeholder:

  • pdfkitAddPlaceholder
  • plainAddPlaceholder

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.

Generate and apply signature

That'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.

Dependencies

node-forge is used for working with signatures.

PDFKit is used in the tests for generating a PDF with a signature placeholder.

Credits

Contributing

Changelog

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].