<?
require($r."vendor/fpdf181/fpdf.php");

if(isset($_POST['snapshot'])){
   $html = stripslashes($_POST['url']); 
   ob_start(); 

?>

<page style="font-size: 14px">
<?php
   echo $html;
?>
</page>
<?php 
   $content = ob_get_clean();
   ob_clean ();


  try
  {
      $html2pdf = new HTML2PDF('P', 'A4', 'en');

      $html2pdf->setDefaultFont('courier');
      $html2pdf->writeHTML($content);
      $file = $html2pdf->Output('temp.pdf','F');
      //pdf creation

      $im = new imagick('temp.pdf');
      $im->setImageFormat( "jpg" );
      $img_name = time().'.jpg';
      $im->setSize(300,200);
      $im->writeImage($img_name);
      $im->clear();
      $im->destroy(); 
      //remove temp pdf
      unlink('temp.pdf');
 }
 catch(HTML2PDF_exception $e) {
    echo $e;
    exit;
 }
}
?>