Forum


Replies: 5   Views: 185
Signpdf throws errorexception in tcpdf_lib.php:20818

Posted by iulian-tsf  · 01-06-2020 - 10:05

Hi,

I'm expericiencing some issues when I try to digitally sign a pdf file. Basically, I'm getting an ErrorException chr() expects parameter 1 to be int, string given, in phpdocx/Classes/Phpdocx/Libs/TCPDF_lib.php, line 20818; I'm not sure if there's something I'm doing wrong at this point or if this is a genuine bug.
Also, forcing a workaround for this, I'm facing some issues with the openssl_pkcs7_sign(): error getting private key thrown from the same file (TCPD_lib.php) from line 32454; after some quick investigations, it seems it expects the cert files to be in the application's public folder.

Just to confirm, signing .docx files works with no issues.

Hopefully there is a workaround for the above issues with pdf sign.

Appreciate your help.

Posted by admin  · 01-06-2020 - 10:29

Hello,

Please try running the included samples (examples/DigitalSignature/signPDF) using PHP CLI mode to check if they works on your server.

Also please send to contact[at]phpdocx.com the PDF document that returns the error, so we can check it.

About your question, the PEM file used to sign the document needs to contain all information (certification and private key), as https://www.phpdocx.com/documentation/introduction/digital-signature-docx-pdf-PHP details. Maybe the PEM file you are using doesn't contain some of the required information? Or OpenSSL can't read it? Please try using the PEM file included in the package as sample ('examples/files/Test.pem').

Regards.

Posted by iulian-tsf  · 01-06-2020 - 10:57

I managed to get the pdf file signed by adding a check for not empty within TCPDF_lib.php in public static function unichr($c, $unicode = true); if empty => return '';

+ for the openssl issue, I had to make sure the pdf sign method does not look for the cert files within the public app folder: I removed the @realpath($dirname(FILE)).'/' from Phpdocx\Sign\SignPDF lines 103 and 104and left them to  $certificate= 'file://' .$this->_x509Certificate;(from$certificate='file://'.@realpath(dirname(FILE)).'/'.$this->_x509Certificate;).

I don't know if this is a fix or I'm simply avoiding some of your internal checks; but even though this is working for me now, I can't actually use this fix as it will mean changing your product and we'll have issues when you'll release a new version. (we are using phpdocx from a private repository).

Re running the included samples: I get the same issues.

If of any interest, I'm running on Alpine Linux with php 7.4.

Posted by admin  · 01-06-2020 - 11:12

Hello,

We have moved the post to the dev team to check both changes to be included in the next release of the library. If you please send a PDF sample that returns the ErrorException chr() expects parameter 1 to be int, string given error to contact[at]phpdocx.com, we are unable to find a PDF that returns the same error.

Regards.

Posted by iulian-tsf  · 01-06-2020 - 11:18

Thanks for your help.

Assume you don't know yet when a new release will happen?

Re pdf file: I'm getting the same ExceptionError when I try the included sample_1.php with phpdocx/phpdocx/examples/files/Test.pdf; but I will also email you the pdf file I'm producing from a docx template; and some screenshots with the issues.

Posted by admin  · 01-06-2020 - 11:27

Hello,

We have been able to replicate the same warning using PHP 7.4. The dev team is checking it.

Regards.