You are viewing limited content. For full access, please sign in.

Question

Question

Workflow - Copy Signature into PDF

asked on November 7, 2014 Show version history

Looking for a way to copy the signature from a Laserfiche Form into a PDF Form. The Fill Out PDF Form activity does not allow access to the signature fields, also how do I access the signature image?

Edit: Here is my final result for a solution.

Note: This may break with future updates to the application since we are calling an internal class.

I found that after a signature was entered a new image is available with class name form-sig-img.

The source of this image is a base64 encoded png.

After the form has been signed extract the source in JavaScript

var data = $('.form-sig-img').attr('src');

Make sure to replace the encoding information in the source right away. (Save to repository is vulnerable to code injection and your data will be replaced with the string "signed").

data = data.replace('data:image/png;base64,','');

Now we just need to put the data in a hidden field so that it can be submitted along with the form. We can create a couple data field with class names (datafield, datafield2) and then hide them.

        $('.datafield').hide();
        $('.datafield2').hide();

I need to diverge for a moment and explain the reason for two data fields.

The maximum field size in Laserfiche is 4000 characters and there are encoded signatures (if drawn) up to around 6000 characters. (If you scribble all over the place you can reach 10k but that is unrealistic). This means you will need to split your data at the 4000 character mark. You can do this with javascript.

Create a function to partition the string.

  function partition(str, index) {
  return [str.substring(0, index), str.substring(index)];
	}

  Then if the data is greater than 4000 characters split the data and put the second half into a second hidden field.

if (data.length < 4001)
      {
        $('.datafield input').val(data);
      } else {
        
        var parts = partition(data, 4000);
        $('.datafield input').val(parts[0]);
        $('.datafield2 input').val(parts[1]);
      }

Whew. Now that this is done setup your save to repository task and drop each data field into a hidden “Text” type field set at 4000 character maximum.

Now we can use Workflow to stamp the image.

First Retrieve the field values and setup a condition for either one field value or both field values containing data.

If both contain data simply re-combine them. I did this in the script.

To place an image onto a PDF you will need a PDF editor library. I used a popular one called iTextSharp. If you are going to distribute this integration make sure to clear up your licensing costs http://itextpdf.com/purchase

Add a script object and under references add the reference to the iTextSharp Libarary (Make sure you are using Workflow 9.2 and the dll file is located directly in the root of the Laserfiche Workflow 9 program files folder.)

Define your master pdf file and your output file.

              string masterFile = "c:\\unsigned.pdf";
              string outputFile = "c:\\signed.pdf";

We also need to decode the encoded png file to a memory stream.

string sigimg = GetTokenValue("RetrieveFieldValues_SigImage").ToString();
byte[] imageBytes = Convert.FromBase64String(sigimg);
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);

Now we can tell iTextSharp to stamp the PDF

 

 using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None))
            {
    PdfStamper stamper = new PdfStamper(new PdfReader(masterFile), fs);

     iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(ms);
                  //Scale it, change the signature size
                    img.ScaleAbsolute(100, 50);
                  //Position it set the position it should appear on the PDF
                    img.SetAbsolutePosition(635, 320);
                  //Add it to page 1 of the document, change 1 to page number
                    stamper.GetOverContent(1).AddImage(img);

                    stamper.Close();

            }

The signature will be stamped directly over the PDF image and will look very natural. No fields required, just need to get the positioning right with trail and error.

 

 

Another option using a more affordable library called Dynamic PDF from ceTe Software. Only the byte array is required, no memory stream.

 

//Load master PDF form
      ceTe.DynamicPDF.Merger.MergeDocument document = new ceTe.DynamicPDF.Merger.MergeDocument("c:\\Laserfiche\\Workflow Files\\masterform.pdf");
            
//Apply License
ceTe.DynamicPDF.Document.AddLicense ( "LICENCE KEY" );

//Create byte array from signature image data
byte[] imageBytes = Convert.FromBase64String(GetTokenValue("RetrieveFieldValues_SigImage").ToString());



            ceTe.DynamicPDF.Imaging.ImageData imgData = ceTe.DynamicPDF.Imaging.ImageData.GetImage(imageBytes);
		//Parameters: Image Byte Array, Y plane from top, X plane from right, transparency in float
            ceTe.DynamicPDF.PageElements.Image image = new ceTe.DynamicPDF.PageElements.Image(imgData, 250, 150, 1.0f);
            image.Width = 100;
            image.Height = 50;
		//The angle gets modified somehow with this library, rotate 270 degrees to set it back to original angle of 0
            image.Angle = 270;
            ceTe.DynamicPDF.PageElements.TransparencyGroup group = new TransparencyGroup(1.0f);
            group.Add(image);
		//Add to page 1, change 0 to the page number you want
            document.Pages[0].Elements.Add(group);
            document.Tag = null;
		//Output File
            document.Draw("c:\\Laserfiche\\Import\\signed.pdf");

 

8 0

Replies

replied on November 7, 2014

Copying a signature from a Form to a PDF is not currently supported.

2 0
replied on November 10, 2014

I don't know about Chads case, but often times, the resulting images of the form saved in the repository are not very pleasant to view.  The page brakes are not configurable and the header is only on the first page.  It is also often desired to have the form saved in the same format that it has been saved in for the last 10+ years.

For these reasons, it is often nice to push the form data into a fallible PDF.  If capturing a signature, it would be very nice to place the signature into this PDF as well.

 

An example of this would be a multiple page consent form that an organization has been using and continues to use for backup, but wants to utilize electronic forms.

2 0
replied on November 10, 2014

I echo what Bert said. One example that I would really like to do is for HR on-boarding to sign in multiple spots with one the same signature. It would be great to be able to have a signed W-4, I-9 etc etc all at once.

0 0
replied on November 10, 2014

This is exactly why, the customer is asking for the final form to look like the original government form was signed.

0 0
replied on November 17, 2014

Thank you all for your feedback on why this feature would be useful. 

Bert, Is the PDF file type a requirement? Or would a TIFF image of a form also be acceptable if the form could be made to look more attractive with, for example, the configurable page breaks and consistent headers that you mention?

0 0
replied on November 17, 2014

Some times, it would be acceptable to just be able to make the saved form more configurable to produce a better flowing resulting document, but more often then not, I think the goal will be to produce an identical replica of the original paper form.

What I have done for my customers so far is to create a workflow that actually pushes the form data into a fillable PDF, convert the resulting PDF to TIFF, and import the TIFF into the repository.  The problem with this is that we can not easily grab the signature during this type of process.

0 0
replied on July 10, 2015

This would be useful to my organization as well. Currently We have a human resources new hire packet on Forms, but because government forms require a wet signature, we still have a few pieces of paper to rpint and scan. 

1 0
replied on November 10, 2014

Hi Chad,

Can you tell us more about the use case? With more information we can better understand how adding such a feature would benefit users.

What role will that signature serve on a PDF? Why do you want to put the signature image on the PDF rather than saving a copy of the signed form directly into the repository from Forms? Whose signature are you capturing, and who will be accessing the signed document?

0 0
replied on November 10, 2014

Hi Chad.

I had the same issue with PDF's being able to be signed. With laserfiche there is away to get this done, but you cannot do it with Workflow.

Here is an example of what I am doing in my HR department to sign documents.

 

I have a "Business Process" that contains all the "Stamps" for the employee's that sign documents. The BP knows exactly where to put the stamp. Remember the Stamp for us is the Signature of the HR Rep hiring the new applicant.

Once the form is filled out, approved etc. We then "Create Pages" to create the needed TIFF images of the document, and then we run the BP to stamp the document. The BP is configured in a way to use NT Authentication to assign the correct stamp with out the user choosing what stamp to use.

After the form is filled out, there is another program that is installed, which came with a "Digital Signature pad" like you use to sign your name when you use your credit card, it captures the image and places the signature on each line that a signature is required. The software interfaces with Laserfiche, it works perfectly.

This process may seem a little long, but trust me, we are able to move people in & out of our hiring center much faster. The normal hire time before Laserfiche was 4 hours, we went down to 15 minutes per person. We are construction and have a high turn around.

0 0
replied on November 10, 2014

Thanks Curtis. Unfortunately these signatures come from a public form, so we can't pre-configure the images.

 

I have a solution, just working out some kinks, will post when finished.

0 0
replied on November 11, 2014

Solution added to original post.

2 0
replied on February 24, 2016

Is converting a signature to a pdf supported in Laserfiche Form 10?

0 0
replied on February 24, 2016

Not currently.

0 0
replied on June 13

How about 10.2?

0 0
replied on June 13

Nope

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.