<?php
include_once(_DIR_TO_CLASS.'/c_page.php') ;
class c_page_cab_test_pdf_sign2 extends c_page
{
  public $h1='Тестирование подписи PDF файлов - встраивание подписи в PDF' ;

  function set_head_tags()
  { parent::set_head_tags() ;
    //$this->HEAD['js'][]=_PATH_TO_EXT.'/jQuery-autoComplete/jquery.auto-complete.js' ;
    //$this->HEAD['css'][]=_PATH_TO_ADDONS.'/html5-file-uploader-master/Content/styles/styles.css' ;
  }


  var $signature_max_length=300000 ;
  var $signature_start=62628 ;
  var $test_dir='ssl_07_11_2016_15_19_40' ;

  function block_main()
  {
    $doc=file_get_contents(_DIR_TO_ROOT.'/cp/debug_sign/'.$this->test_dir.'/doc.pdf') ;

    $signature=file_get_contents(_DIR_TO_ROOT.'/cp/debug_sign/'.$this->test_dir.'/sign.txt') ;
    // decode signature
    $signature = base64_decode(trim($signature));
    // add TSA timestamp to signature
    //$signature = $this->applyTSA($signature);
    // convert signature to hex
    $signature = current(unpack('H*', $signature));
    echo 'Итоговый размер подписи:'.strlen($signature).'<br>' ;
    $signature = str_pad($signature, $this->signature_max_length, '0');


    $new_doc=substr_replace($doc,$signature,$this->signature_start,$this->signature_max_length) ;
    file_put_contents(_DIR_TO_ROOT.'/cp/debug_sign/'.$this->test_dir.'/new_doc.pdf',$new_doc) ;

    $this->page_title() ;
    ?><iframe src="/cp/debug_sign/<? echo $this->test_dir?>/new_doc.pdf"  style="width:100%; height:700px;margin-top:20px;" frameborder="0"></iframe><?
  }
}




?>