Insert digital signature field into dynamically-created PDF

Viewed 260

I'm trying to dynamically create a PDF, of which a user can control by editing the templated text of and then download it from the browser. The templated text is controlled through storing a CLOB in the database. That's all fine and easy, but I also need to add a digital/electronic signature field at the bottom of the generated PDF. I've found little documentation on this, but it seems the ColdFusion way of doing this is to use a cfpdf action="sign", with the documentation giving this as an example:

<cfpdf action="sign"
source="#inputfilepath##inputfilename#"
destination="#signedfilepath##signedfilename#"
keystore="#certpath#cert.pfx" keystorepassword="certpass"
overwrite="true" pages="1" height="100"
width="100" position="100,100" author="false"
/>

The file path to the ColdFusion server's keystore is "C:/Program Files/jdk-11.0.10/lib/security/cacerts/". There appears to be no cert file in there. Would one need generated by using keytool in the command line, as referenced here?

My second option (after cfpdf) seems to be implementing the iText library through cfscript, since ColdFusion is Java-driven and runs on a JVM. Here is a mockup I was able to create that might result in something I'm looking for:

<cfscript>
    resource = CreateObject("java", "java.io.FileInputStream");
    resource.init("C:\path\OriginalLetter.pdf");
    os = CreateObject("java", "java.io.FileOutputStream");
    os.init("C:\path\NewLetter.pdf");
    annotation = CreateObject("java", "com.itextpdf.text.pdf.PdfAnnotation");
    annotation.init();
    reader = CreateObject("java", "com.itextpdf.text.pdf.PdfReader");
    reader.init(resource);
    stamper = CreateObject("java", "com.itextpdf.text.pdf.PdfStamper");
    stamper.init(reader, os);
    FormField = CreateObject("java", "com.itextpdf.text.pdf.PdfFormField");
    FormField.init();
    field = FormField.createSignature(stamper.getWriter());
    field.setFieldName("Signature");
    field.setWidget(new Rectangle(30, 830, 170, 770), annotation.HIGHLIGHT_NONE);
    stamper.addAnnotation(field, 1);
    stamper.close();
</cfscript>

But there seems to be uncertainty if such an implementation would be functional on ColdFusion's side.

Again, there seems to be little I can find on this and could use some guidance from people experienced in ColdFusion administration or even in a problem similar to this. My backup plan is to put the actual template PDF file - which already has the signature block at the bottom - on the server file system and then the user can simply edit the text within from there, and the signature field would stay at the bottom. To explain this better, the templated text I use from the DB is based off the contents of this file; it's just I can't store something like a PDF digital signature field as text. More specifically, I am using HTML to generate the content so it can be formatted better. The user can edit the text through a ckeditor on the browser, but again, a simple input would not render as a signature field on a PDF.

1 Answers

You may have found a solution already, but you are able to add formfields using the Adobe Sign API. I mention it because you are looking to have people sign the document.

I haven't used it myself ( yet ), but I too need to do the same after creating a pdf with Coldfusion's CFDOCUMENT.

Adobe Acrobat Sign API - FAQ

There is a monetary cost with using the API however, but perhaps the workflow of collecting signatures may suit you.

Related