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

PDF version #4

Closed herzhy closed 3 years ago

herzhy commented 3 years ago

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

dealfonso commented 3 years ago

Thank you for your interest. Could you please attach a PDF that fails, and the command or code used?

herzhy commented 3 years ago

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');
                }
            }
        }
    }`
dealfonso commented 3 years ago

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.

herzhy commented 3 years ago
Thank you for your attentionI will try it again Sent from Mail for Windows From: Carlos de AlfonsoSent: 17 August 2021 23:11To: dealfonso/sappCc: herzhy; State changeSubject: Re: [dealfonso/sapp] PDF version (#4) Closed #4.—You are receiving this because you modified the open/close state.Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android.