-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce examples of JS and TS usage of the most popular scenario
- Loading branch information
Showing
6 changed files
with
186 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ yarn-error.log* | |
|
||
coverage | ||
.coveralls.yml | ||
packages/examples/output | ||
|
||
node_modules/ | ||
.npm | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"private": true, | ||
"name": "@signpdf/examples", | ||
"version": "3.0.2", | ||
"description": "", | ||
"scripts": { | ||
"js": "node src/javascript.js", | ||
"ts": "ts-node src/typescript.ts" | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vbuch/node-signpdf.git" | ||
}, | ||
"dependencies": { | ||
"@signpdf/placeholder-plain": "^3.0.2", | ||
"@signpdf/signpdf": "^3.0.2", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.2.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/plugin-transform-modules-commonjs": "^7.23.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var plainAddPlaceholder = require('@signpdf/placeholder-plain').plainAddPlaceholder | ||
var signer = require('@signpdf/signpdf').default; | ||
|
||
function work() { | ||
// contributing.pdf is the file that is going to be signed | ||
var sourcePath = path.join(__dirname, '/../../../resources/contributing.pdf'); | ||
var pdfBuffer = fs.readFileSync(sourcePath); | ||
|
||
// certificate.p12 is the certificate that is going to be used to sign | ||
var certificatePath = path.join(__dirname, '/../../../resources/certificate.p12'); | ||
var certificateBuffer = fs.readFileSync(certificatePath); | ||
|
||
// The PDF needs to have a placeholder for a signature to be signed. | ||
var pdfWithPlaceholder = plainAddPlaceholder({ | ||
pdfBuffer: pdfBuffer, | ||
reason: 'The user is decalaring consent through JavaScript.', | ||
contactInfo: 'signpdf@example.com', | ||
name: 'John Doe', | ||
location: 'Free Text Str., Free World', | ||
}); | ||
|
||
// pdfWithPlaceholder is now a modified buffer that is ready to be signed. | ||
var signedPdf = signer.sign(pdfWithPlaceholder, certificateBuffer); | ||
|
||
// signedPdf is a Buffer of an electronically signed PDF. Store it. | ||
var targetPath = path.join(__dirname, '/../output/javascript.pdf'); | ||
fs.writeFileSync(targetPath, signedPdf); | ||
} | ||
|
||
work(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import fs from 'fs'; | ||
import { plainAddPlaceholder } from '@signpdf/placeholder-plain'; | ||
import signer from '@signpdf/signpdf' | ||
|
||
function work() { | ||
// contributing.pdf is the file that is going to be signed | ||
const pdfBuffer = fs.readFileSync(`${__dirname}/../../../resources/contributing.pdf`); | ||
// certificate.p12 is the certificate that is going to be used to sign | ||
const certificateBuffer = fs.readFileSync(`${__dirname}/../../../resources/certificate.p12`); | ||
|
||
// The PDF needs to have a placeholder for a signature to be signed. | ||
const pdfWithPlaceholder = plainAddPlaceholder({ | ||
pdfBuffer, | ||
reason: 'The user is decalaring consent.', | ||
contactInfo: 'signpdf@example.com', | ||
name: 'John Doe', | ||
location: 'Free Text Str., Free World', | ||
}); | ||
|
||
// pdfWithPlaceholder is now a modified buffer that is ready to be signed. | ||
const signedPdf = signer.sign(pdfWithPlaceholder, certificateBuffer); | ||
|
||
// signedPdf is a Buffer of an electronically signed PDF. Store it. | ||
const targetPath = `${__dirname}/../output/typescript.pdf`; | ||
fs.writeFileSync(targetPath, signedPdf); | ||
} | ||
|
||
work(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig.json", | ||
"extends": "ts-node/node12/tsconfig.json", | ||
"include": [ | ||
"src/**/*.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters