sapp icon indicating copy to clipboard operation
sapp copied to clipboard

Option to update existing signature box (instead of always creating a new one)

Open ridgey-dev opened this issue 11 months ago • 3 comments

Right now the PDFDoc::_generate_signature_in_document always creates a new annotation object. I would like to have the functionality to update an existing signature box.

For now I extended the PDFDoc object, so that it does:

$annotationObject = $this->get_object($this->signatureBoxId);

instead of

PDFDoc::449
$annotation_object = $this->create_object([
                "Type" => "/Annot",
                "Subtype" => "/Widget",
                "FT" => "/Sig",
                "V" => new PDFValueString(""),
                "T" => new PDFValueString('Signature' . get_random_string()),
                "P" => new PDFValueReference($page_obj->get_oid()),
                "Rect" => $recttoappear,
                "F" => 132  // TODO: check this value
            ]
        );

I created the setSignatureBoxId(int $signatureBoxId) function to set the signature box ID that will be updated. This function checks if the given ID is an existing signature box (correct type/subtype etc.)

ridgey-dev avatar Jan 06 '25 12:01 ridgey-dev

Feel free to make a PR with the fix

angeljqv avatar Jan 06 '25 13:01 angeljqv

I do not know what is your use case. Could you please tell us about it? Is it of general interest?

dealfonso avatar Jan 06 '25 19:01 dealfonso

I do not know what is your use case. Could you please tell us about it? Is it of general interest?

The use case for this functionality is to work with documents that already contain predefined, unsigned signature boxes. These boxes are typically included in the document as placeholders to visually indicate to the end user where their signature will appear after signing.

Currently, the package automatically creates a new signature box with a random name for every signature action. This behavior leads to PDFs that contain both the newly created (signed) signature box and the original (unsigned) placeholder, which is not ideal for workflows where maintaining the integrity of pre-existing placeholders is critical.

To address this, I have created a pull request to enable the functionality of updating existing signature boxes instead of creating new ones. This enhancement ensures that the package can effectively handle documents with predefined signature placeholders without introducing redundancies. You can view the pull request here for further details: #89 Option to update existing signature box (instead of always creating a new one

I believe this improvement aligns with the needs of users working with preformatted documents and would be of general interest to those looking for a seamless signing process in such cases.

ridgey-dev avatar Jan 07 '25 08:01 ridgey-dev