Hello,
we’re generating PDFs for our client. In that generated PDF there are some inputs plus two signatures. Our goal is when the user signs one of the signatures, then we want to lock All or just some of the inputs. There is a checkbox in Adobe Acrobat Reader, which is asking if you want to lock document after signing, but our client does not want to check this checkbox manually, but do it automatically. We know that it’s possible, but I cannot find the proper solution.

We’re using TCPDF library, which is written in PHP. There is no such option to make that signature lock the PDF(investigated source of that library). I assume that I need to make that option to that library – add some options from specification. I found in the officicial specification( https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdf_reference_archive/pdf_reference_1-7.pdf – page 695 and lower) “how” to do it, or how it is possible, but I cannot make it work.

PHP code that is generating signature field in TCPDF library:

if (!empty($this->empty_signature_appearance)) {
foreach ($this->empty_signature_appearance as $key => $esa) {
$actionObj = $this->_getobj();
// widget annotation for empty signature
$out = $this->_getobj($esa['objid'])."n";
$out .= '<< /Type /Annot';
$out .= ' /Subtype /Widget';
$out .= ' /Rect ['.$esa['rect'].']';
$out .= ' /P '.$this->page_obj_id[($esa['page'])].' 0 R'; // link to signature appearance page
$out .= ' /F 4';
//$out .= ' /BS /S';
//$out .= ' /BS /U';
$out .= ' /FT /Sig';
$signame = $esa['name'].sprintf(' [%03d]', ($key + 1));
$out .= ' /T '.$this->_textstring($signame, $esa['objid']);
$out .= ' /Ff 0';
$out .= ' >>';
$out .= "n".'endobj';
$this->_out($out);
}
}

I tried to add to code below:

$out .= ' /FT /Sig /Lock 54 0';

plus create new object with id 54 0(code bellow should somehow reference to this new created object):

$out = $actionObj . "n";
$out .= '<</Action/All/Type/SigFieldLock>>';
$out .= "n".'endobj';
$this->_out($out);

The 54 0 is $actionObj identifier – I put it statically just to test.
But whatever change I make, the signature dissapears.
There is also some posibility to do some things with javascript, which can be linked on generation time, but then problem with rights appears, because function setLock is protected and cannot be called in my case.

Javascript is wrong way I guess, because someone could revert it later if only inputs were marked as readonly. So I will not discuss it this way.
I assume that the way of generating pdf with that functionality in it with /Lock is proper way instead of JS, but I cannot make it really work. I tried to find something on the internet, but nothing works for me. Does anyone here have experience with generating PDFs? Thanks.

I’d suggest reposting this in r/phphelp as this isn’t a support subreddit. However, doing any automatic change to PDFs is very difficult. TCPDF might just not have the support for this feature. It might be worth getting in contact with a paid PDF library that might have more features and be able to guide you to the solution.

Thank you guys for your kindness. I finally found the solution after like 3 days 😀 . I will make pull request to that library and post the results here soon.

I’d advise to check out the libraries from Setasign.
They have some public and some paid libraries which help with handling pdf’s. They might have something that works for you.

source