A javascript tool to sign a pdf in web browser, google apps script and nodejs.
 
 
 
 
Go to file
zboris12 213cf53474 Improve samples in readme. 2022-09-17 22:08:29 +09:00
.gitignore The first commit. 2022-09-17 21:55:09 +09:00
LICENSE Initial commit 2022-09-17 21:48:13 +09:00
README.md Improve samples in readme. 2022-09-17 22:08:29 +09:00
test.html The first commit. 2022-09-17 21:55:09 +09:00
zgapdfsigner.js The first commit. 2022-09-17 21:55:09 +09:00

README.md

ZgaPdfSigner

A javascript tool to sign a pdf in web browser.

PS: ZGA is the abbreviation of my father's name.
And I use this name to hope the merits from this application will be dedicated to my parents.

The Dependencies

How to use this tool

Just import the dependencies and this tool.

<script src="https://unpkg.com/pdf-lib/dist/pdf-lib.min.js" type="text/javascript"></script>
<script src="https://unpkg.com/node-forge/dist/forge.min.js" type="text/javascript"></script>
<script src="https://github.com/zboris12/zgapdfsigner/releases/download/1.0.0/zgapdfsigner.js" type="text/javascript"></script>

Let's sign

Sign with an invisible signature.

/**
 * @param {ArrayBuffer} pdf
 * @param {ArrayBuffer} cert
 * @param {string} pwd
 * @return {Promise<Blob>}
 */
async function sign1(pdf, cert, pwd){
  /** @type {SignOption} */
  var sopt = {
    p12cert: cert,
    pwd: pwd,
  };
  var signer = new PdfSigner(sopt);
  return await signer.sign(pdf);
}

Sign with a visible signature of a picture.

/**
 * @param {ArrayBuffer} pdf
 * @param {ArrayBuffer} cert
 * @param {string} pwd
 * @param {ArrayBuffer} imgdat
 * @param {string} imgtyp
 * @return {Promise<Blob>}
 */
async function sign2(pdf, cert, pwd, imgdat, imgtyp){
  /** @type {SignOption} */
  var sopt = {
    p12cert: cert,
    pwd: pwd,
    drawinf: {
      area: {
        x: 25,  // left
        y: 150, // top
        w: 60,  // width
        h: 60,  // height
      },
      imgData: imgdat,
      imgType: imgtyp,
    },
  };
  var signer = new PdfSigner(sopt);
  return await signer.sign(pdf);
}

Sign with a visible signature of drawing a text.

//TODO

Detail of SignOption

  • p12cert: string 👉 A raw data of the certificate
  • pwd: string 👉 The passphrase of the certificate
  • reason: string 👉 (Optional) The reason for signing
  • location: string 👉 (Optional) Your location
  • contact: string 👉 (Optional) Your contact information
  • signdate: Date 👉 (Optional) The date and time of signing
  • signame: string 👉 (Optional) The name of the signature
  • drawinf: SignDrawInfo 👉 (Optional) Visible signature's information
    • area: SignAreaInfo 👉 The signature's drawing area
      • x: number 👉 Distance from left
      • y: number 👉 Distance from top
      • w: number 👉 Width
      • h: number 👉 Height
    • pageidx: number 👉 (Optional) The page index for drawing the signature
    • imgData: Uint8Array|ArrayBuffer|string 👉 (Optional) The image's data
    • imgType: string 👉 (Optional) The image's type, only support jpg and png
    • text: string 👉 (Optional) A text drawing on signature, not implemented yet
    • fontData: PDFLib.StandardFonts|Uint8Array|ArrayBuffer|string 👉 (Optional) The font's data for drawing text, not implemented yet

License

This tool is available under the MIT license.