souravlahoti
12/16/2018 - 3:52 PM

FDA digi sign

Tried signing FDA pdf using NoPodofo

import { nopodofo as npdf, NPDFAnnotationFlag, NPDFAnnotation, pdfDate } from 'nopodofo'
const doc = new npdf.Document()
console.log(doc);
doc.load('./FDA.pdf', e => {

    console.log(e);
    const rect = new npdf.Rect(0, 0, 10, 10),
        page = doc.getPage(0),
        annot = page.createAnnotation(NPDFAnnotation.Widget, rect)

    // This signature is going to be hidden, for a visible signature add an appearance stream
    annot.flags = NPDFAnnotationFlag.Hidden | NPDFAnnotationFlag.Invisible

    const field = new npdf.SignatureField(annot, doc)

    // Set field properties
    field.setReason('test')
    field.setLocation('here')
    field.setCreator('me')
    field.setFieldName('signer.sign')

    // This will set the date as now
    field.setDate()
    // or create a new date and pass to the setDate function
    let d = new npdf.Date(pdfDate(new Date('2012-12-12')))
    field.setDate(d)
    const signer = new npdf.Signer(doc, './output/')
    signer.signatureField = field
    signer.loadCertificateAndKey('certificate.p12', 'withpass.p12', (error, signatureLength) => {
        if (error) { /* handle error */ }
        signer.write(signatureLength, (e, d) => {
            if (e) { /* handle error*/ }
            // signed document has been written to /output/path provided in Signer constructor 
        })
    })
})