zgapdfsigner
A javascript tool to sign a pdf in web browser, google apps script and nodejs.
AI Summary
ZgaPdfSigner
Tool to sign/protect PDFs in web browser, GAS, Node.js.
Target Users
Mid-level JS devs solving PDF signing/protection in GAS/Node.js.
Problems Solved
Lack of libraries for PKCS#7 signing or RC4/AES protection of PDFs in browser/GAS/Node.js.
Script ID
- In GAS Editor: Click "Libraries +" → Paste into "Script ID" field → Click "Look up"
- "zgapdfsigner" will appear in the search results
- Select the latest version (highest number) from "Version" dropdown
- Click "Add"
Tags
Main Features
1
Various Signatures
Invisible/visible (image/text) signatures, multi-page, TSA timestamp, LTV, incremental updates.
2
Rich Protection
RC4(40/128bit)/AES(128/256bit) password/pubkey cert protection, DocMDP permissions.
3
Multi-Platform
Works in web browser, Google Apps Script, Node.js using pdf-lib/node-forge.
Examples
Main Functions
| Function | Description |
|---|---|
| new Zga.PdfSigner(sopt) | Create PdfSigner instance with SignOption |
| signer.sign(pdf, eopt?) | Sign PDF (with optional encrypt simultaneously) |
| new Zga.PdfCryptor(eopt) | Create PdfCryptor instance with EncryptOption |
Examples
Invisible Signing
/**
* 不可視署名
* ・署名オプション設定: { p12cert: cert, pwd: pwd, permission: 1 }
* ・PdfSignerインスタンス作成: new Zga.PdfSigner(sopt)
* ・署名実行: await signer.sign(pdf)
*/
async function signInvisible(pdf, cert, pwd){
var sopt = {
p12cert: cert,
pwd: pwd,
permission: 1,
};
var signer = new Zga.PdfSigner(sopt);
var u8arr = await signer.sign(pdf);
return new Blob([u8arr], {"type" : "application/pdf"});
}Visible Signing (Image)
/**
* 可視署名(画像)
* ・描画領域設定: drawinf.area = {x:25, y:150, w:60, h:60}
* ・画像情報設定: imgInfo = {imgData: imgdat, imgType: imgtyp}
* ・署名実行: await signer.sign(pdf)
*/
async function signVisibleImage(pdf, cert, pwd, imgdat, imgtyp){
var sopt = {
p12cert: cert,
pwd: pwd,
drawinf: {
area: {
x: 25,
y: 150,
w: 60,
h: 60,
},
imgInfo: {
imgData: imgdat,
imgType: imgtyp,
},
},
};
var signer = new Zga.PdfSigner(sopt);
var u8arr = await signer.sign(pdf);
return new Blob([u8arr], {"type" : "application/pdf"});
}Password Protection
/**
* パスワード保護
* ・暗号オプション設定: {mode: Zga.Crypto.Mode.RC4_40, userpwd: upwd, ownerpwd: opwd}
* ・PdfCryptorインスタンス作成: new Zga.PdfCryptor(eopt)
* ・暗号化実行: await cyptor.encryptPdf(pdf); pdfdoc.save()
*/
async function protectPassword(pdf, upwd, opwd){
var eopt = {
mode: Zga.Crypto.Mode.RC4_40,
permissions: ["modify", "annot-forms", "fill-forms", "extract", "assemble"],
userpwd: upwd,
ownerpwd: opwd,
};
var cyptor = new Zga.PdfCryptor(eopt);
var pdfdoc = await cyptor.encryptPdf(pdf);
var u8arr = await pdfdoc.save({"useObjectStreams": false});
return new Blob([u8arr], {"type" : "application/pdf"});
}