Advertisement
Guest User

Untitled

a guest
Jul 4th, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. <?php
  2.     //get content from digitally signed pdf
  3.     $pdf_contents = file_get_contents($path_to_pdf);
  4.  
  5.     //get the signature string at the end of the file, starting from "/ByteRange"
  6.     $pdf_contents = substr($pdf_contents, strpos($pdf_contents, '/ByteRange'));
  7.     $pdf_contents_string = $pdf_contents;
  8.     $pdf_contents_string = explode(">", $pdf_contents_string);
  9.     $signature_content = $pdf_contents_string[0].'>';
  10.    
  11.     // this the signature string value if I echo $signature_content at this point
  12.     // /ByteRange[0 49443 61187 6424] /Contents<30820bb506092a864886f70d010702a0820ba630...> /Name (��OpenStudio) /Location (��OpenStudio Digital Signature) /Reason (��DS) /ContactInfo (��https://www.openstudio.one) /M (D:20230629231908+02'00')
  13.    
  14.     $result = [];
  15.     $regexp = '/\/ByteRange\[\s*(\d+) (\d+) (\d+) (\d+)] \/Contents\<\s*(\w+)>/';
  16.  
  17.     //SCENARIO B - replace content of $signature_content with the one coming from doing the echo
  18.     //$signature_content = "/ByteRange[0 49443 61187 6424] /Contents<30820bb506092a864886f70d010702a0820ba630...>";
  19.     preg_match_all($regexp, $signature_content, $result);
  20.  
  21.     $signatures = [];
  22.    
  23.     //in "correct" scenario A, the outcome of var_dump() is array(6) { [0]=> array(0) { } [1]=> array(0) { } [2]=> array(0) { } [3]=> array(0) { } [4]=> array(0) { } [5]=> array(0) { } } array(0) { }
  24.     //in scenario B, where $signature_content content is replaced manually with the same content coming from its echo, the outcome is correct
  25.     //array(6) { [0]=> array(1) { [0]=> string(11784) "/ByteRange[0 49443 61187 6424] /Contents<30820bb506092a864886f70d010..." } } array(1) { [0]=> string(23) "username_test" }
  26.     var_dump($result);
  27.    
  28.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement