Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //get content from digitally signed pdf
- $pdf_contents = file_get_contents($path_to_pdf);
- //get the signature string at the end of the file, starting from "/ByteRange"
- $pdf_contents = substr($pdf_contents, strpos($pdf_contents, '/ByteRange'));
- $pdf_contents_string = $pdf_contents;
- $pdf_contents_string = explode(">", $pdf_contents_string);
- $signature_content = $pdf_contents_string[0].'>';
- // this the signature string value if I echo $signature_content at this point
- // /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')
- $result = [];
- $regexp = '/\/ByteRange\[\s*(\d+) (\d+) (\d+) (\d+)] \/Contents\<\s*(\w+)>/';
- //SCENARIO B - replace content of $signature_content with the one coming from doing the echo
- //$signature_content = "/ByteRange[0 49443 61187 6424] /Contents<30820bb506092a864886f70d010702a0820ba630...>";
- preg_match_all($regexp, $signature_content, $result);
- $signatures = [];
- //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) { }
- //in scenario B, where $signature_content content is replaced manually with the same content coming from its echo, the outcome is correct
- //array(6) { [0]=> array(1) { [0]=> string(11784) "/ByteRange[0 49443 61187 6424] /Contents<30820bb506092a864886f70d010..." } } array(1) { [0]=> string(23) "username_test" }
- var_dump($result);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement