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

Question

Question

Copying a Stamp via SDK

asked on August 18, 2023 Show version history

We're trying to build a WF that triggers when a specific stamp gets created and then propagates that stamp to all subsequent pages of the document.  I've got the code working, but in this case the stamp we're copying contains a %(Date) token in it.  I can get it to replicate the stamp properly, but the copies have the literal %(Date) text in the stamp instead of resolving to the actual date.  I've tried a handful of different properties, replacing CustomData properties, etc. but I can't get it to change to the actual date.  Any ideas on this one?  Basic Rough Code below:

 dim doc as DocumentInfo = Document.GetDocumentInfo(integer.Parse(GetTokenValue("Entry ID")),RASession)
       dim anns = doc.GetAnnotations

    for each ann as AnnotationBase in anns
        if ann.AnnotationType = AnnotationType.Stamp Then
            dim annstamp as StampAnnotation = ann
           
           
            dim stampid as Integer
            if annstamp.CustomData.StartsWith("REC'D %(Date)") Then
                if annstamp.CustomData.EndsWith("FAX") Then
                    stampid = 87
                    Else
                    stampid = 86
                    end If  
                for p as Integer = annstamp.PageNumber + 1 to doc.PageCount
                    dim page as PageInfo = doc.GetPageInfo(p)
                    dim si as StampInfo = Stamp.GetInfo(stampid, RASession)   
                    dim ns as new StampAnnotation(doc, p, si)
                    
                    ns.Coordinates = annstamp.Coordinates
                    ns.Color = annstamp.Color
                    ns.Position = annstamp.Position
                    Page.AddAnnotation(ns)
                    page.Save
next
End If
End If
Next
 

 

 

 

 

 

0 0

Answer

SELECTED ANSWER
replied on August 18, 2023 Show version history

If all you want to do is replicate the same stamp image across multiple pages, then you shouldn't have to deal with retrieving stamp ids or resolving tokens.

Instead. you can just create an entirely new stamp object and copy the image data from the existing stamp rather than trying to "regenerate" the same stamp again.

The following is in C# but it is a working example where the target document is passed in as the script's Default Entry and the stamp image is replicated to each subsequent page.

// get document info
DocumentInfo doc = (DocumentInfo)BoundEntryInfo;

// iterate document annotations
foreach(AnnotationBase ann in doc.GetAnnotations()){
    // check for stamps with appropriate custom data
    if (ann.AnnotationType == AnnotationType.Stamp && ann.CustomData.StartsWith("REC'D %(Date)")){
        // cast as stamp annotation
        StampAnnotation stamp = (StampAnnotation)ann;

        // iterate document pages
        for (int p = stamp.PageNumber + 1; p <= doc.PageCount; p++){
            // create stamp info and copy image data
            StampInfo stampInfo = new StampInfo(RASession);
            stampInfo.ImageData = stamp.Bitmap;

            // create stamp object on document page
            StampAnnotation newStamp = new StampAnnotation(doc, p, stampInfo);

            // set stamp properties and save
            newStamp.Coordinates = stamp.Coordinates;
            newStamp.Color = stamp.Color;
            newStamp.Position = stamp.Position;
            // saving the page/document separately is not necessary
            // because we provided a doc/page in the parameters
            newStamp.Save();
        }
    }
}

1 0
replied on August 23, 2023

The idea of copying the bitmap property to the imageData of a new stamp worked.  For some reason my original code for getting the stamps CustomData property no longer worked when I came back, all my stamps were now blank with this property,  but I was able to work around it with some creative starting rules.  Thanks for getting me in the right direction.

0 0

Replies

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

Sign in to reply to this post.