Closed herzhy closed 3 years ago
Thank you for your interest. Could you please attach a PDF that fails, and the command or code used?
here is my code and attachment example pdf document version 1.7 and I want to save the signed doc in other path like (/assets/doc/..) thanks before
List Usulan Pemkab 2021 new.pdf
$filename = str_replace(' ', '', $data['personal_doc']['document_name'] . '_Sign_' . date('YmdHis') . '.pdf');
$pass = $this->input->post('password');
$pdf_path = dirname(dirname(__DIR__));
$file_before_signed = $this->input->post('document_file');
$data['signature'] = $this->db->get_where('signature', ['user_id' => $data['user']['id']])->row_array();
if (!file_exists($pdf_path . '/assets/doc/' . $file_before_signed))
// fwrite(STDERR, "failed to open file " . $argv[1]);
$this->session->set_flashdata('message', '<div class="alert alert-danger" role="alert">
file not found !
</div>');
else {
// Silently prompt for the password
// fwrite(STDERR, "Password: ");
// system('stty -echo');
// $password = trim(fgets(STDIN));
// system('stty echo');
// fwrite(STDERR, "\n");
$file_content = file_get_contents($pdf_path . '/assets/doc/' . $file_before_signed);
$obj = PDFDoc::from_string($file_content);
if ($obj === false)
//fwrite(STDERR, "failed to parse file " . $argv[1]);
$this->session->set_flashdata('message', '<div class="alert alert-danger" role="alert">
failed to parse file!
</div>');
else {
// $obj->set_signature_certificate($pdf_path . '/assets/crt/' . $data['signature']['certificate'], $pass);
$obj->set_signature_certificate($pdf_path . '/assets/crt/Hersyam.pfx', $pass);
$docsigned = $obj->to_pdf_file($filename);
if ($docsigned === false) {
// fwrite(STDERR, "could not sign the document");
$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">
could not sign the document!
</div>');
} else {
$this->db->set('document_file', $filename);
$this->db->where('id', $this->input->post('proses_id'));
$this->db->update('proses');
$this->db->set('date_signed', time());
$this->db->where([
'proses_id' => $this->input->post('proses_id'),
'role_id' => $data['user']['role_id']
]);
$this->db->update('document_role');
$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">
Signature Success..!
</div>');
redirect('proses/my_doc');
}
}
}
}`
Hi,
sorry but I have tried the relevant code and there is no error with the provided pdf file. Maybe it has to do with other issue (e.g. check if var $file_before_signed
is an empty string).
You can check the commandline php pdfsign.php "List Usulan Pemkab 2021 new.pdf" Hersyam.pfx
and it does not complain about the file, and generates the proper signed file.
Hello Mr Alfonso Thanks for creating this library that made me learn a lot, so my question is in what version this library will run perfectly? because i'd try with pdf 1.3 or 1.4 , it running well, but with pdf 1.7 it didn't work, always "failed to parse file "
thank you for your attention and explanation