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

There's just one more problem with my signature pictures #11

Closed lemsn closed 1 year ago

lemsn commented 2 years ago

Why does the signature picture automatically turn 90 degrees clockwise?

图片

The original picture looks like this 图片

lemsn commented 2 years ago

signature pdf file: output_852.pdf

original pdf file:

myTest.pdf

dealfonso commented 2 years ago

Hi,

the "problem" of that document is that the pages are already rotated 90 degrees, and how PDF works... if the page is rotated, the image should be rotated too, but sapp does not provide support for rotating images, at this moment.

Sorry.

lemsn commented 2 years ago

But I use another tool for signature: TCPDI, and the signature picture is not rotated.

image

signature pdf file:

94cd0147-7810-421c-a0fc-4c91d07e47c6.pdf

What is the reason for this.

dealfonso commented 2 years ago

Hi,

sorry, but I do not know about the internals of TCPDI. Perhaps they rotate the image.

lemsn commented 2 years ago

No, that's not what it means. With their tool, the image doesn't rotate, but when I used SAPP, sometime , the image rotated,

lemsn commented 2 years ago

So, my solution is to rebuild my PDF file using TCPDF, and then use SAPP to sign my new PDF. This solves two problems:

  1. Picture rotation problem 2, sometimes, read PDF: the Error on the read some PDF: Invalid string (https://github.com/dealfonso/sapp/issues/10).

I still enjoy using SAPP. Can you help with that in future releases?

lemsn commented 2 years ago

In addition, I also found the location and size of sapp's signature pictures inconvenient, so I used the method of TCPDF for your reference and improvement:


/ *
// Add the following method to line 13567: \vendor\tecnickcom\ TCPDF \tcpdf.php
      public function getAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
      return $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
}
* /
$this->pdf = new TCPDI(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 
$Appearance = $this->pdf->getAppearance(130, 150, 40, 40);  

PS: 
130   The X coordinate of the picture
150   The Y coordinate of the picture
40     Image width
40     Image height

By this calculation, we get: rect

$rect = explode(' ',$Appearance['rect']);
$x = $rect[0];            
$y = $rect[1];            
$w = $rect[2];          
$h = $rect[3];          

// Set the image appearance and certificate file
$obj ->set_signature_appearance(0, [ $x, $y, $w, $h ], $image);
//$obj->set_signature_appearance(0, [ $p_x, $p_y, $p_x + $i_w, $p_y + $i_h ], $image);
$obj ->et_signature_certificate($cert, $password);
dealfonso commented 2 years ago

If you have managed to solve the problem... are you willing to contribute to the code via pull request?

dealfonso commented 2 years ago

So, my solution is to rebuild my PDF file using TCPDF, and then use SAPP to sign my new PDF. This solves two problems:

  1. Picture rotation problem 2, sometimes, read PDF: the Error on the read some PDF: Invalid string (Error on read some PDF:Invalid string #10).

I still enjoy using SAPP. Can you help with that in future releases?

I have created a solution for #10. Could you please test it?

lemsn commented 2 years ago

`

`

If you have managed to solve the problem... are you willing to contribute to the code via pull request?

code file:

SappController.php.TXT

Akshay2323 commented 2 years ago

What is Token: image

MoisesAlvesSousa commented 2 years ago

I have a file with several pages in pdf, I wanted to put the graphic signature on each one as $obj->set_signature_appearance(0, [ $p_x, $p_y, $p_x + $i_w, $p_y + $i_h ], $image); I created a loop but it is only on the last page. Would you like to do that?

dealfonso commented 2 years ago

Hi, sorry but according to the PDF structure, each signature can appear only once per signature process. So calling set_signature_appearance simply updates the placement.

dealfonso commented 1 year ago

Hi @lemsn

I have added a solution to the rotated appearance issue. Would you like to try it?

dealfonso commented 1 year ago

closing it because there is no activity and seems to be solved