dealfonso / sapp

Simple and Agnostic PDF Document Parser in PHP - sign PDF docs using PHP
GNU Lesser General Public License v3.0
115 stars 30 forks source link

Call to a member function set_signature_certificate() on bool #20

Closed MartinKravec closed 2 years ago

MartinKravec commented 2 years ago

Hey guys :)

could you help me with this problem?

I am running the following code outside CLI in Laravel 9 with PHP 8.1.9 but I am getting:

"Call to a member function set_signature_certificate() on bool" in browser and "Error info at /Users/martinkravec/git/angel/vendor/ddn/sapp/src/PDFUtilFnc.php:377: PDF version string not found " in stderr.log.

use ddn\sapp\PDFDoc;

if (!defined('STDERR')) define('STDERR', fopen(__DIR__ . '/../../../storage/logs/stderr.log', 'wb'));

require_once(__DIR__ . '/../../../vendor/autoload.php');

$fileContent = file_get_contents('./file.pdf');
$obj = PDFDoc::from_string($fileContent);
$certificatePath = __DIR__ . '/../../../storage/app/test_certificate.pfx';

$password = '';
$obj->set_signature_certificate($certificatePath, $password);

When I do cat ./file.pdf, I get file content starting with:

HTTP/1.0 200 OK
Cache-Control:       no-cache, private
Content-Disposition: inline; filename="document.pdf"
Content-Type:        application/pdf
Date:                Sun, 28 Aug 2022 09:37:03 GMT

%PDF-1.7
1 0 obj
<< /Type /Catalog
/Outlines 2 0 R
/Pages 3 0 R >>
endobj
2 0 obj
<< /Type /Outlines /Count 0 >>
endobj
3 0 obj
<< /Type /Pages
/Kids [6 0 R
19 0 R
]
/Count 2
/Resources <<
/ProcSet 4 0 R
/Font << 
/F1 8 0 R
/F2 13 0 R
>>
/XObject << 
/I1 18 0 R
>>
>>
/MediaBox [0.000 0.000 595.280 841.890]
 >>
endobj
4 0 obj
[/PDF /Text /ImageC ]
endobj
5 0 obj
<<
/Producer (��dompdf 2.0.0 + CPDF)
/CreationDate (D:20220828113702+02'00')
/ModDate (D:20220828113702+02'00')
/Title (��D�vky.PDF)
>>
endobj
6 0 obj
<< /Type /Page
/MediaBox [0.000 0.000 595.280 841.890]
/Parent 3 0 R
/Contents 7 0 R
>>
endobj
7 0 obj
<< /Filter /FlateDecode
/Length 919 >>
stream
MartinKravec commented 2 years ago

I just resolved the problem https://stackoverflow.com/questions/73517867/call-to-a-member-function-set-signature-certificate-on-bool/73518244#73518244