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

Question

Question

Secure stamp to be applied by a workflow

asked on November 9, 2020 Show version history

I would like to create a stamp with the signature of an executive, and have a workflow apply it. Unfortunately, I just found out that workflow can only apply public stamps, which means that any Laserfiche user will be able to apply this stamp to any document they are allowed to annotate.

Is there a way around this?

Is there any thought of enhancing workflow to allow it to apply personal stamps associated with the service account used to run the workflow?

0 0

Answer

SELECTED ANSWER
replied on November 11, 2020 Show version history

I wouldn't really say it was obvious, but when you start writing the code the script editor does help a bit in identifying types. The sImage is a Bitmap type, in this example it's being created dynamically based on image data retrieved from a Form field, which is in turn created by an HTML canvas element, so I'm not sure you'd need to go that route.

In your case it sounds like you'd be using pre-generated stamps, so you'd probably want to use the StampInfo object. You can retrieve StampInfo objects either by Id, or by name.

Id is something you'd need to find ahead of time either by checking the database or by running a script to search for it, so name may be the easiest.

What you'd do to prepare is sign into the repository as the user Workflow uses to connect to the repository and creating the stamps under that user.

So if you use an account like WorkflowUser for your connection profile, sign into the repository as that user and create all your "secure" stamps under that account and set them to private (It sounds like you already did this, but I'm including it anyway in case someone else stumbles across this).

Now, they'll belong to that user and you should be able to retrieve them by name using the Stamp.GetInfoPersonal method like so,

// set stamp position
LfSize sSize = new LfSize(sWidth, sHeight);
LfPoint sPoint = new LfPoint(x,y);

// get stamp by name
StampInfo sInfo = Stamp.GetInfoPersonal("STAMP",RASession);

// apply stamp
StampAnnotation stamp = new StampAnnotation(docInfo,pageNumber,sInfo);
stamp.Coordinates = new LfRectangle(sPoint,sSize);
stamp.Color = LfColor.BLACK;
stamp.ZOrder = 9999999;
stamp.Save();

The key here is making sure of the following:

  • The connection profile is using the same account you used to log in and created the stamps
  • Your stamp names match the stamps you created
1 0

Replies

replied on November 10, 2020

I've done stuff like this with SDK scripts. I'm thinking it's just the Apply Stamp activity that is limited to Public stamps because when you do it through an SDK Script WF seems to have access to create/use "private" stamps just like a normal user would.

int sWidth = Convert.ToInt32(sImage.Width * scale);
int sHeight = Convert.ToInt32(sImage.Height * scale);

// set stamp position
LfSize sSize = new LfSize(sWidth, sHeight);
LfPoint sPoint = GetStampPosition(xPos, yPos, sSize, sRotation, page, scale, sType);

// create and apply stamp object
StampAnnotation stamp = new StampAnnotation(doc,pageNumber,GetStampData(sImage),sWidth,sHeight);
stamp.Coordinates = new LfRectangle(sPoint,sSize);
stamp.Color = GetStampColor(sColor);
stamp.ZOrder = 9999999;
stamp.Save();

 

1 0
replied on November 11, 2020

This may be obvious to those familiar with SDK Scripts, but where do you get sImage? What data type is it?

0 0
SELECTED ANSWER
replied on November 11, 2020 Show version history

I wouldn't really say it was obvious, but when you start writing the code the script editor does help a bit in identifying types. The sImage is a Bitmap type, in this example it's being created dynamically based on image data retrieved from a Form field, which is in turn created by an HTML canvas element, so I'm not sure you'd need to go that route.

In your case it sounds like you'd be using pre-generated stamps, so you'd probably want to use the StampInfo object. You can retrieve StampInfo objects either by Id, or by name.

Id is something you'd need to find ahead of time either by checking the database or by running a script to search for it, so name may be the easiest.

What you'd do to prepare is sign into the repository as the user Workflow uses to connect to the repository and creating the stamps under that user.

So if you use an account like WorkflowUser for your connection profile, sign into the repository as that user and create all your "secure" stamps under that account and set them to private (It sounds like you already did this, but I'm including it anyway in case someone else stumbles across this).

Now, they'll belong to that user and you should be able to retrieve them by name using the Stamp.GetInfoPersonal method like so,

// set stamp position
LfSize sSize = new LfSize(sWidth, sHeight);
LfPoint sPoint = new LfPoint(x,y);

// get stamp by name
StampInfo sInfo = Stamp.GetInfoPersonal("STAMP",RASession);

// apply stamp
StampAnnotation stamp = new StampAnnotation(docInfo,pageNumber,sInfo);
stamp.Coordinates = new LfRectangle(sPoint,sSize);
stamp.Color = LfColor.BLACK;
stamp.ZOrder = 9999999;
stamp.Save();

The key here is making sure of the following:

  • The connection profile is using the same account you used to log in and created the stamps
  • Your stamp names match the stamps you created
1 0
replied on November 11, 2020

Thank you, I think this gives me enough to make it work.

0 0
replied on November 17, 2022

Jason,

 can you please let me know what references I need to include for this? I get error that GetStampPosition is not found. I am trying to retrieve signature from Forms and apply as a stamp using workflow, thanks.

0 0
replied on November 17, 2022

Hi Priya,

GetStampPosition is a custom method to calculate stamp coordinates based on my particular scenario and the scaling used in our implementation.

It returns an LfPoint(x,y) object, which is what you really need.

 

0 0
replied on November 17, 2022

Thanks. Do you have code on how to get the signature field from Forms and assign it to sImage please?

0 0
replied on November 17, 2022

I do not have any sample code for that.

0 0
replied on November 17, 2022

Thanks. Are methods 'GetStampData' and 'GetStampColor' custom as well?

0 0
replied on November 17, 2022

Yes. 

GetStampData just converts a Bitmap object into a byte array, which is what you need as the 3rd parameter for a new StampAnnotation object depending on which overload you're using.

        private static byte[] GetStampData(Bitmap img){
            // convert stamp bitmap into byte array
            using(MemoryStream os = new MemoryStream()){
                // convert image and extract byte data
                img.Save(os, ImageFormat.Bmp);
                byte[] bytes = os.ToArray();
                int blength = bytes.Length-14;
                byte[] imgData = new byte[blength];
                Array.Copy(bytes,14,imgData,0,blength);

                // return byte array of image data
                return imgData;
            }
        }

GetStampColor just returns a LfColor object, which we only needed because the color is dynamic based on user input.

In your case, you could probably just use LfColor.BLACK but that might be the default anyway in which case you wouldn't need to set it at all.

0 0
replied on November 17, 2022

Thanks. Do I need to add any reference for ImageFormat?

0 0
replied on November 17, 2022

It's from System.Drawing.Image

 

0 0
replied on November 17, 2022

Thanks

0 0
replied on November 17, 2022

Everything is good now, the only part missing is that I do not know how to get the Signature field from Forms into the workflow Bitmap object.

0 0
replied on November 18, 2022

What is the usual value set for scale?

0 0
replied on November 18, 2022

Scale is really dependent upon your specific situation. We use scale because our page sizes can vary depending on the document source.

If your pages are fairly consistent in their pixel dimensions, then you may not need the scale variable at all.

0 0
replied on November 21, 2022

Thanks

0 0
replied on November 18, 2022 Show version history

In Workflow, you must retrieve the Form variables using a Retrieve Business Process Variables activity.

The Signature variable starts with header or metadata information that tells you it is an image of png format and in a Base64 String.  Then it has the base64 image data.

In your script activity, you need to load the signature data and strip off the leading header/metadata.

Now the sSignature object holds the Base64 image data.  To convert this to an image, you must load it into a Byte Array, then into a MemoryStream, and then into an Image.

This gets you mostly what you need, but will fail as a stamp because the stamp requires a black and white bitmap and the image loaded from the Base64 data is not black and white.  See ConvertToBitonal function in this post.

Now you have a Black and White Bitmap, but it is stamping as a black block.  This is because the original data has a transparent background that is being set by default to dark/black.  To fix this, you must create a new Bitmap object, get the Graphics portion of it, set the background to White, and then write the image data from the image created from the Base64 data.  Once you have the signature with a white background, convert that image to black and white and use it in your stamp.

1 0
replied on November 21, 2022

Thanks, will try

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

Sign in to reply to this post.