<?php
// Image Plus Text PDF  ... RJM Programming ... August 2022
require('MarkItUp/fpdf17/fpdf.php');
//if (1 == 1) {
//echo "<html><body><p>gfdg nhffd</p></body></html>";
//exit;
//} else 

class RPDF extends FPDF { // thanks to http://www.fpdf.org/en/script/script31.php

function TextWithDirection($x, $y, $txt, $direction='R')
{
    if ($direction=='R')
        $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',1,0,0,1,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
    elseif ($direction=='L')
        $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',-1,0,0,-1,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
    elseif ($direction=='U')
        $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',0,1,-1,0,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
    elseif ($direction=='D')
        $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',0,-1,1,0,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
    else
        $s=sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
    if ($this->ColorFlag)
        $s='q '.$this->TextColor.' '.$s.' Q';
    $this->_out($s);
}

function TextWithRotation($x, $y, $txt, $txt_angle, $font_angle=0)
{
    $font_angle+=90+$txt_angle;
    $txt_angle*=M_PI/180;
    $font_angle*=M_PI/180;

    $txt_dx=cos($txt_angle);
    $txt_dy=sin($txt_angle);
    $font_dx=cos($font_angle);
    $font_dy=sin($font_angle);

    $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',$txt_dx,$txt_dy,$font_dx,$font_dy,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
    if ($this->ColorFlag)
        $s='q '.$this->TextColor.' '.$s.' Q';
    $this->_out($s);
}

}

$user_agent = $_SERVER['HTTP_USER_AGENT']; 

function server_remote_addr() {
    $rma = $_SERVER['REMOTE_ADDR'];
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    // you can add different browsers with the same way ..
    if (1 == 2) {
    if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
            $rma = '000000'.$rma;
    elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
            $rma = '00000'.$rma;
    elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
            $rma = '0000'.$rma;
    elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
            $rma = '000'.$rma;
    elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
            $rma = '00'.$rma;
    elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
            $rma = '0'.$rma;
    }
    return "_" . str_replace(".", "_", str_replace(":", "_", $rma));
}

if (isset($_GET['pdffile'])) {
   $val=str_replace('+',' ',urldecode($_GET['pdffile']));
   if (strpos($val, ".") !== false) {
    if (strtolower(explode(".", basename($val))[-1 + sizeof(explode(".", basename($val)))]) == 'pdf') {
     $ourfname=str_replace('.pdf','',str_replace('.PDF','',basename($val)));
     if (1 == 1) {
   if (strpos( $user_agent, 'Safari') !== false && strpos( $user_agent, 'Chrome') === false && strpos( $user_agent, 'OPR') === false && strpos( $user_agent, 'Firefox') === false && strpos( $user_agent, 'Opera') === false) {
       $wobit="window.open('/" . $ourfname . ".pdf','_blank');";
       echo '<html><body onclick="' . $wobit . '" title="Click for PDF and/or scroll down to Sharing section" style="background:URL(' . 'data:image/jpeg;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.jpg')) . ');background-repeat:no-repeat;background-size:contain;"><img title="Click for PDF and/or scroll down to Sharing section" style=visibility:hidden; onclick="' . $wobit . '" src="' . 'data:image/jpeg;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.jpg')) . '"></img></body></html>';
   } else {
       echo '<html><body><div style="overflow:auto;-webkit-overflow-scrolling:touch;height:100%;"><object style="width:100%;height:900px;" type="application/pdf" data="' . 'data:application/pdf;base64,' . base64_encode(file_get_contents('./' . basename($val))) . '">' . "\n" . '<embed style="width:100%;height:900px;" type="application/pdf" src="' .'data:application/pdf;base64,' . base64_encode(file_get_contents('./' . basename($val))) . '"></embed></object></div></body></html>'; 
   }
     } else {
       header('Content-Type: application/pdf');
       echo file_get_contents('./' . basename($val));
     }
    } else {
     header('Content-Type: image/' . strtolower(explode(".", basename($val))[1]));
     echo file_get_contents('./' . basename($val));
    }
   }
   exit;   
} else if (1 == 7 && isset($_GET['justiurl'])) {
   echo "<html>
<body style='background:" . urldecode($_GET['justiurl']) . ";background-repeat:no-repeat;'>
</body>
</html>";
   exit;
} else if (1 == 7 && isset($_POST['justiurl'])) {
   echo "<html>
<body style='background:URL(" . urldecode($_POST['justiurl']) . ");background-repeat:no-repeat;'>
</body>
</html>";
   exit;
} else if (strlen('' . $_SERVER['QUERY_STRING']) <= 1) { //strpos($_SERVER['REQUEST_URI'], '?'))
   if (!isset($_POST['pdfimageplustext'])) {
   echo "<html>
<head>
<style>

 .custom-alert {
  display: inline-block;
  /* visibility: visible; */
  background-color: rgba(102,102,102,0.8);
  color: #fff;
  text-align: enter;
  margin: 5% auto;
  padding: 12px 28px;
  opacity: 0.9;
  z-index: 200;
  -webkit-animation: glow 1s linear infinite alternate;
  -moz-animation: glow 1s linear infinite alternate;
  animation: glow 1s linear infinite alternate;
 }

 /* Thanks to https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_glowing_text */

 @-webkit-keyframes glow {
  from {
    box-shadow: 0 0 3px #fff, 0 0 5px #fff, 0 0 37px #e60073, 0 0 9px #e60073, 0 0 11px #e60073, 0 0 13px #e60073, 0 0 15px #e60073;
  }

  to {
    box-shadow: 0 0 24px #fff, 0 0 6px #ff4da6, 0 0 8px #ff4da6, 0 0 10px #ff4da6, 0 0 12px #ff4da6, 0 0 14px #ff4da6, 0 0 16px #ff4da6;
  }
 }


</style>
<script type='text/javascript'>

var datauri='';
var coordn=1;
var x=-1, y=-1;
var startrecording=false;
var ontox='';
var nofiddling=false;


function maybemore() {
}

function iifopen(iois) {
  if (iois != null) {
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto.document) { aconto = aconto.document; }
    if (aconto != null) {
      if (aconto.getElementById('distyle')) {
        aconto.getElementById('distyle').innerHTML+='<style> input[type=file]::file-selector-button { background-color: pink; } </style>';
        aconto.getElementById('files').accept='image/*';
      }
    }
  }
}

function addtoform(withwhat) {
  if (withwhat.trim() != '') {
    if (x >= 0 && y >= 0) {
      document.getElementById('coords').innerHTML+='<input type=hidden name=pdfx' + coordn + ' value=\"' + ('' + x).split('.')[0] + ontox + '\"></input>';
      document.getElementById('coords').innerHTML+='<input type=hidden name=pdfy' + coordn + ' value=\"' + ('' + y).split('.')[0] + '\"></input>';
      document.getElementById('coords').innerHTML+='<input type=hidden name=pdftext' + coordn + ' value=\"' + withwhat + '\"></input>';
      coordn++;
      ontox='';
      startrecording=false; 
    }
  }
}

function analyze(inans) {
  var zeroes='';
  var ffst=',Courier,Helvetica,Arial,Times,Symbol,ZapfDingbats,';
  var fss=',regular,normal, ,B,bold,I,italic,itallic,U,underline,';
  var outans=inans;
  var arris=inans.split(';');
  if (arris.length > 1) {
    for (var iarris=0; iarris<eval(-1 + eval('' + arris.length)); iarris++) {
      if ((arris[iarris] + ' ').substring(0,1) >= '0' && (arris[iarris] + ' ').substring(0,1) <= '9') {
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontsize').value='' + arris[iarris];
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontsize name=pdffontsize value=\"' + arris[iarris] + '\"></input>';
          }
        }
        ontox='.' + zeroes + arris[iarris];
        outans=outans.replace(arris[iarris] + ';', '');
      } else if (ffst.toLowerCase().indexOf(',' + arris[iarris].toLowerCase() + ',') != -1) {
        outans=outans.replace(arris[iarris] + ';', '');
        if (document.getElementById('pdffamily')) {
          document.getElementById('pdffamily').value=arris[iarris].substring(0,1).toUpperCase() + arris[iarris].substring(1).toLowerCase().replace('apfdingbats','apfDingbats');
        } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffamily name=pdffamily value=' + arris[iarris].substring(0,1).toUpperCase() + arris[iarris].substring(1).toLowerCase().replace('apfdingbats','apfDingbats') + '></input>';
        }
      } else if (fss.toLowerCase().indexOf(',' + arris[iarris].toLowerCase() + ',') != -1) {
        switch (fss.toLowerCase()) {
          case 'regular':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value=' ';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\" \"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='0';
        }
            break;
          case 'normal':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value=' ';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\" \"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='0';
        }
            break;
          case 'b':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='B';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"B\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='0000';
        }
            break;
          case 'bold':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='B';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"B\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='0000';
        }
            break;
          case 'i':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='I';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"I\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='00';
        }
            break;
          case 'italic':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='I';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"I\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='00';
        }
            break;
          case 'itallic':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='I';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"I\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='00';
        }
            break;
          case 'u':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='U';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"U\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='000';
        }
            break;
          case 'underline':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='U';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"U\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='000';
        }
            break;
          default:
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value=' ';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\" \"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='0';
        }
            break;
        }
      }
    }
  }
  if (ontox == '' && zeroes != '') { ontox='.' + zeroes; }
  return outans;
}

function askaway() {
  if (startrecording) {
  var ans=' ';
  ans=prompt('Enter with nothing to proceed.  Else enter text number ' + coordn + ' to place where last click was made.  Optionally prefix by text Font Family (for all text if Arial no good versus Courier or Helvetica or Arial or Times or Symbol or ZapfDingbats);Font Style (double semicolon delimit for all text default if Bold no good else single semicolon delimit for this text only versus Normal or Italic or Bold or Underline);Font Size in px (for this text if 16px no good) delimited by semicolon.','');
  if (ans == null) { ans=''; }
  if (analyze(ans).trim() == '') { startrecording=false; document.getElementById('myform').submit();  } else { addtoform(ans); setTimeout(askaway, 5000);   }
  }
}


function redraw() {
  document.getElementById('cbi').style.display='none'; 
  document.getElementById('myp').style.display='none'; 
  document.getElementById('iurl').style.display='none'; 
  document.getElementById('relfind').style.display='none'; 
  document.getElementById('myptwo').style.display='none'; 
  document.getElementById('myh1').style.display='none'; 
  document.getElementById('myh3').style.display='none'; 
  document.getElementById('mybody').style.background='url(' + datauri + ')';
  document.getElementById('mybody').style.backgroundRepeat='no-repeat';
  document.getElementById('slideshow').name='pdfimage';
  if (document.body.outerHTML.indexOf('url(') != -1) {
    datauri=document.body.outerHTML.split('url(')[1].split(')')[0].replace(/\&quot\;/g,''); //.replace(/\'/g,'').replace(/\\\"/g,'');
  }
  document.getElementById('slideshow').value=datauri;
  //alert(datauri.substring(0,100) + ' ... ' + document.body.outerHTML.substring(0,350));
  document.getElementById('coords').innerHTML+='<input type=hidden name=pdfimageplustext value=y></input>';
  startrecording=true;
  document.getElementById('mybody').onclick=function(e){
    e = e || window.event;
    e.preventDefault();
       startrecording=true;
       if (e.touches) {
       if (e.touches[0].pageX) {
       x = e.touches[0].pageX;
       y = e.touches[0].pageY;
       askaway();
       } else {
       x = e.touches[0].clientX;
       y = e.touches[0].clientY;
       askaway();
       }
       //console.log('pos3=' + pos3 + ',pos4=' + pos4);
       } else if (e.clientX || e.clientY) {
        x = e.clientX;
        y = e.clientY;
       askaway();
       } else {
        x = e.pageX;
        y = e.pageY;
       askaway();
       }
  };
  document.getElementById('mybody').title='Click where text is to be placed in your resultant PDF'; //setTimeout(askaway, 5000); //alert('am here');
  document.body.innerHTML+=\"<div id=custom-alert-1 class=custom-alert style='position:fixed; left: 50%; transform: translate(-50%, -50%); top:50%; display: block;'>Click where text node(s) are to be placed in your resultant PDF.  You will get prompted for optional styling options.</div>\";
  setTimeout(hideIt, 10000);
 }

 function hideIt() {
  document.getElementById('custom-alert-1').style.display='none';
 }

function lookfordatauri() {
  if (datauri == '' && document.getElementById('slideshow').value.trim() != '') {
    //datauri=' ';
    //setTimeout(lookfordatauri, 19000);
  //} else if (datauri .trim()== '' && document.getElementById('slideshow').value.trim() != '') {
    if (nofiddling) {
    datauri=document.getElementById('slideshow').value;
    } else {
    datauri=document.getElementById('slideshow').value.replace(/^\.\.\//g, '').replace(/^\.\//g, 'PHP/');
    document.getElementById('slideshow').value=datauri;
    }
    //document.getElementById('slideshow').value='';
    redraw(); //document.getElementById('isub').click();
  } else {
    setTimeout(lookfordatauri, 1000);
  }
}

function setjust(ino) {
  var szc='';
  var trc='';
  var lastcis=-1;
  if (ino.value.trim() != '') {
    var hases=ino.value.split('#');
    if (hases.length > 1) {
      if (hases[1].trim() != '') {
        var coms=hases[1].split(',');
        if (hases[1].toLowerCase().indexOf('rgb') == 0) {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfrtext name=pdfrtext value=' + hases[1].split('(')[1].split(',')[0] + '></input>';
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfgtext name=pdfgtext value=' + hases[1].split('(')[1].split(',')[1] + '></input>';
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfbtext name=pdfbtext value=' + hases[1].replace(')',',').split('(')[1].split(',')[2] + '></input>';
          hases[1]=hases[1].replace(hases[1].split(')')[0] + ')', '').trim();
        }
        if (ino.value.replace(hases[0] + '#','').indexOf('px') != -1) {
          while ((' ' + ino.value.replace(hases[0] + '#','').split('px')[0]).slice(lastcis).substring(0,1) >= '0' && (' ' + ino.value.replace(hases[0] + '#','').split('px')[0]).slice(lastcis).substring(0,1) <= '9') {
            szc=(' ' + ino.value.replace(hases[0] + '#','').split('px')[0]).slice(lastcis);
            lastcis--;
          }
          hases[1]=hases[1].replace(szc + 'px', '').trim();
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontsize name=pdffontsize value=' + szc + '></input>'; 
        }
        lastcis=1;
        if ((hases[1] + ' ').substring(0,1) >= '0' && (hases[1] + ' ').substring(0,1) <= '9') {
          while ((hases[1] + ' ').substring(0,lastcis).slice(-1) >= '0' && (hases[1] + ' ').substring(0,lastcis).slice(-1) <= '9') {
            trc+=(hases[1] + ' ').substring(0,lastcis).slice(-1);
            lastcis++;
          }
          hases[1]=hases[1].replace(trc + '', '').trim();
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfrotatetextdeg name=pdfrotatetextdeg value=' + trc + '></input>'; 
        }
        if (hases[1].indexOf('Normal') != -1) {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdfdfontstyle value=\" \"></input>'; 
          hases[1]=hases[1].replace('Normal', '').trim();
        }
        if (hases[1].indexOf('Bold') != -1) {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdfdfontstyle value=\"B\"></input>'; 
          hases[1]=hases[1].replace('Bold', '').trim();
        }
        if (hases[1].indexOf('Ital') != -1) {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdfdfontstyle value=\"I\"></input>'; 
          hases[1]=hases[1].replace('Italic', '').replace('Itallic', '').trim();
        }
        if (hases[1].indexOf('Underline') != -1) {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdfdfontstyle value=\"U\"></input>'; 
          hases[1]=hases[1].replace('Underline', '').trim();
        }
        if (hases[1].indexOf('R') != -1) { 
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfdirectiontext name=pdfdirectiontext value=R></input>'; 
        } else if (hases[1].indexOf('L') != -1) { 
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfdirectiontext name=pdfdirectiontext value=L></input>'; 
        } else if (hases[1].indexOf('U') != -1) { 
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfdirectiontext name=pdfdirectiontext value=U></input>'; 
        } else if (hases[1].indexOf('D') != -1) { 
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfdirectiontext name=pdfdirectiontext value=D></input>'; 
        }
      }
      document.getElementById('iurl').value=hases[0].trim() ; //ino.value.split('#')[0];
    }
    if (hases[0].trim() != '') {
    nofiddling=true;
    document.getElementById('slideshow').value=ino.value.split('#')[0];
    lookfordatauri(); //document.getElementById('isub').click();
    nofiddling=false;
    }
  }
}

setTimeout(lookfordatauri, 1000);

</script>
</head>
<body id=mybody>
<iframe onload='iifopen(this);' id='cbi' frameborder='0' style='width:173px;height:228px;margin-top:-194px;' src='/HTMLCSS/client_browsing.htm?d=10562686'></iframe>
<p id=myp> ... or ...<hr></p>
<h1 id=myh1>Image and Text Nodes PDF Creation</h1>
<h3 id=myh3>RJM Programming - August, 2022</h3>
<input style='width:100%;' id=iurl type=url placeholder='Image Relative URL (hash value can define a text colour for the PDF eg. #rgb(0,0,255) and/or text rotation in degrees and/or px font size [16] and/or R or L or U or D text direction and/or Normal or Bold or Italic or Underline text style [Bold])' value='' onblur='setjust(this);'></input>
<p id=myptwo> ... or ...<hr></p>
<iframe id=relfind src='/PHP/find_images_via_size.php?fillps=y' style='width:100%;height:900px;'></iframe>
<form id=myform method=POST action=./pdfimageplustext.php style=display:none;>
<input type=hidden id=slideshow name=justiurl value=''></input> 
<div id=coords style=display:none;></div>
<input type=submit id=isub style=display:none; value='Ask for Text'></input>
</form>
</body>
</html>";
     exit;
   }
}

$ourfname="filename" . server_remote_addr();
$dru="http://" . $_SERVER['SERVER_NAME'] . "" . str_replace("~","",str_replace(":443~","",str_replace(":80~","",(":" . $_SERVER['SERVER_PORT'] . "~")))) . "/";
$linkemailshare=$dru . $ourfname . ".pdf#Your Image and Text PDF#Via RJM Programming";
$sharehtmlbit="<br><br><iframe src='" . str_replace('http:','',str_replace("rjmprogramming.com.au/","rjmprogramming.com.au/HTMLCSS/",$dru)) . "web_share_api_test.html?suggestion=" . urlencode($linkemailshare) . "' style='width:100%;height:900px;'></iframe>";
$safarisharehtmlbit='open "' . str_replace("rjmprogramming.com.au/","rjmprogramming.com.au/HTMLCSS/",$dru) . 'web_share_api_test.html?suggestion=' . urlencode($linkemailshare) . '"';

$furl=((isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER[HTTP_HOST] . str_replace("HTTP:","http:",$_SERVER[REQUEST_URI]));
$dpath=str_replace("$#$","//", explode("/",str_replace("//","$#$",$furl))[0] ) . "/";
$frest=explode(((isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER[HTTP_HOST] . "/"),   ((isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER[HTTP_HOST] . str_replace("HTTP:","http:",$_SERVER[REQUEST_URI]))   )[1];
if (strpos(($frest . '*'), '=*') === false && strpos($frest, "=") !== false) {
  $frest=explode("=", $frest)[0] . "=";
}
//echo $furl . " ... " . $dpath . " ... " . $frest;
//exit;
$sincebefore="";
$prefix="";
$notprefix="";
for ($i=0; $i<(-1 + sizeof(explode("/",$frest))); $i++) {
  $notprefix=explode($frest,$furl)[0];
  $prefix.="../";
}
if ($prefix == "") $notprefix="";
$first=true;
$outputto="";
$outputsofar="";
$outputpdf=null;
$top=1;
$title="";
$wastitle="";
$istitle="";
$cpn=1;
$emailto="";
$pdfis="";
$outputpdf_hgt=100.0;
$lh=6;
$loffset=0;
$fpdfs=",Arial,Courier,Helvetica,Symbol,Times,ZapfDingbats,";

$scale=floatval(1.0);
$scalep=floatval(100.0);

if (isset($_POST['pdfimageplustext'])) {
   $w=0;
   $h=0;
   $outputpdf = new RPDF('P','pt');
   //if (isset($_POST['pdfrtext']) && isset($_POST['pdfgtext']) && isset($_POST['pdfbtext'])) {
   //$outputpdf->SetTextColor(urldecode($_POST['pdfrtext']), urldecode($_POST['pdfgtext']), urldecode($_POST['pdfbtext']));
   //}
   $outputpdf->SetTopMargin(0.0);
   //$outputpdf->AddPage('L');
   if (isset($_POST['pdfimage'])) {
    $inval=$_POST['pdfimage'];
    //if (strpos(urldecode($inval), "data:image/") === false && strpos(urldecode($inval), "data:") !== false && strpos(urldecode($inval), ";base64,") !== false) {
    //  $inval=urlencode('data:image/jpeg;base64,' . explode(";base64,", urldecode($inval)));
    //}
    if (strpos(urldecode($inval), "data:image/") !== false && strpos(urldecode($inval), ";base64,") !== false) {
    $fname='./' . $ourfname . '.' . strtolower(explode(";", explode("data:image/", urldecode($inval))[1])[0]);
    file_put_contents($fname, base64_decode(str_replace(' ','+',explode(";base64,", urldecode($inval))[1])));
    list($w, $h) = getimagesize($fname);
    if ($w > $h) {
    $outputpdf->AddPage('L', 'A4');
    if ($w > 830) {
    $scale=floatval(830.0 / $w);
    $scalep=floatval($scale * 100.0);
    //$outputpdf->_out('q');
    //Scale(floatval($scalep), floatval($scalep));
    $newh=($h * (830.0 / $w));
    $outputpdf->Image($fname, 0, 0, 830, floatval($newh)); //, 33.78);
    //$outputpdf->_out('Q');
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    } else {
    $outputpdf->AddPage('P', 'A4');
    if ($h > 830) {
    $scale=floatval(830.0 / $h);
    $scalep=floatval($scale * 100.0);
    //Scale(floatval($scalep), floatval($scalep));
    $neww=($w * (830.0 / $h));
    $outputpdf->Image($fname, 0, 0, floatval($neww), 830); //, 33.78);
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    }
    } else if (strpos(urldecode($_POST['pdfimage']), "rjmprogramming.com.au/") !== false) {
    $fname="./" . explode(')',explode('&quot;',explode("rjmprogramming.com.au/", urldecode($_POST['pdfimage']))[1])[0])[0];
    //$outputpdf->Image("./" . explode("rjmprogramming.com.au/", urldecode($_POST['pdfimage']))[1], 0, 0); //, 33.78);
    list($w, $h) = getimagesize($fname);
    if ($w > $h) {
    $outputpdf->AddPage('L', 'A4');
    if ($w > 830) {
    $scale=floatval(830.0 / $w);
    $scalep=floatval($scale * 100.0);
    //$outputpdf->_out('q');
    //Scale(floatval($scalep), floatval($scalep));
    $newh=($h * (830.0 / $w));
    $outputpdf->Image($fname, 0, 0, 830, floatval($newh)); //, 33.78);
    //$outputpdf->_out('Q');
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    } else {
    $outputpdf->AddPage('P', 'A4');
    if ($h > 830) {
    $scale=floatval(830.0 / $h);
    $scalep=floatval($scale * 100.0);
    //Scale(floatval($scalep), floatval($scalep));
    $neww=($w * (830.0 / $h));
    $outputpdf->Image($fname, 0, 0, floatval($neww), 830); //, 33.78);
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    }
    } else {
    if (strpos(urldecode($_POST['pdfimage']), 'url(') !== false) {
    $fname=str_replace('&quot;','',explode(')',explode('url(',urldecode($_POST['pdfimage']))[1])[0]);
    } else {
    $fname=urldecode($_POST['pdfimage']);
    }
    file_put_contents('x.x', $fname);
    //$outputpdf->Image(urldecode($_POST['pdfimage']), 0, 0); //, 33.78);
    list($w, $h) = getimagesize($fname);
    if ($w > $h) {
    $outputpdf->AddPage('L', 'A4');
    if ($w > 830) {
    $scale=floatval(830.0 / $w);
    $scalep=floatval($scale * 100.0);
    //$outputpdf->_out('q');
    //Scale(floatval($scalep), floatval($scalep));
    $newh=($h * (830.0 / $w));
    $outputpdf->Image($fname, 0, 0, 830, floatval($newh)); //, 33.78);
    //$outputpdf->_out('Q');
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    } else {
    $outputpdf->AddPage('P', 'A4');
    if ($h > 830) {
    $scale=floatval(830.0 / $h);
    $scalep=floatval($scale * 100.0);
    //Scale(floatval($scalep), floatval($scalep));
    $neww=($w * (830.0 / $h));
    $outputpdf->Image($fname, 0, 0, floatval($neww), 830); //, 33.78);
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    }
    }
   } else {
    $outputpdf->AddPage('L','A4');
   }
   
   if (isset($_POST['pdftext1'])) {
   $texti=1;
   $ffy='Arial';
   $fst='B';
   $fsz=16;
   if (isset($_POST['pdffamily'])) {
     $ffy=str_replace('+',' ',urldecode($_POST['pdffamily']));
   }
   if (isset($_POST['pdffontstyle'])) {
     $fst=str_replace('N',' ',substr(strtoupper(str_replace('+',' ',urldecode($_POST['pdffontstyle']))) . ' ',0,1));
   }
   if (isset($_POST['pdffontsize'])) {
     if (strlen(trim(str_replace('+',' ',urldecode($_POST['pdffontsize'])))) > 0) {
       $fsz=str_replace('+',' ',urldecode($_POST['pdffontsize']));
     }
   }
   $ofsz=$fsz;
   $ofst=$fst;
   while (isset($_POST['pdftext' . $texti]) && isset($_POST['pdfx' . $texti]) && isset($_POST['pdfy' . $texti])) {
     $exc="~";
     if (strpos(urldecode($_POST['pdfx' . $texti]), '.') !== false && strpos(urldecode($_POST['pdfy' . $texti]), '.') === false) {
       $fsz=explode('.', urldecode($_POST['pdfx' . $texti]))[1];
       if (substr('' . $fsz . '   ',4) == '0000') {
         $fst='B';
         $fsz=substr($fsz,4);
         if ($fsz == '') { $fsz=$ofsz;  }
       } else if (substr('' . $fsz . '   ',3) == '000') {
         $fst='U';
         $fsz=substr($fsz,3);
         if ($fsz == '') { $fsz=$ofsz;  }
       } else if (substr('' . $fsz . '  ',2) == '00') {
         $fst='I';
         $fsz=substr($fsz,2);
         if ($fsz == '') { $fsz=$ofsz;  }
       } else if (substr('' . $fsz . ' ',1) == '0') {
         $fst=' ';
         $fsz=substr($fsz,1);
         if ($fsz == '') { $fsz=$ofsz;  }
       } 
       $exc=".";
     }
     if (strlen(trim(urldecode($_POST['pdftext' . $texti]))) > 0) {
     //echo "yesooo";
     //exit;
       $outputpdf->SetFont($ffy,$fst,$fsz);
       $ourx=floatval($scale * floatval(explode($exc, urldecode($_POST['pdfx' . $texti]))[0]));
       $oury=floatval($scale * floatval(urldecode($_POST['pdfy' . $texti])));
       $stris=str_replace('^%&',' + ',str_replace('+',' ',str_replace('+++','^%&',urldecode($_POST['pdftext' . $texti]))));
   if (isset($_POST['pdfrtext']) && isset($_POST['pdfgtext']) && isset($_POST['pdfbtext'])) {
   $outputpdf->SetTextColor(urldecode($_POST['pdfrtext']), urldecode($_POST['pdfgtext']), urldecode($_POST['pdfbtext']));
   }
       if (isset($_POST['pdfdirectiontext'])) {
       $outputpdf->TextWithDirection($ourx,$oury,$stris,$_POST['pdfdirectiontext']);
       } else if (isset($_POST['pdfrotatetextdeg'])) {
       $outputpdf->TextWithRotation($ourx,$oury,$stris,$_POST['pdfrotatetextdeg'],0); 
       } else {
       $outputpdf->Text($ourx,$oury,$stris); 
       }    
     }
     $texti++;
     $fsz=$ofsz;
     $fst=$ofst;
   }
   }
   if (file_exists('./' . $ourfname . '.pdf')) {    unlink('./' . $ourfname . '.pdf');   }
   $outputpdf->Output("./" . $ourfname . ".pdf", "F");
   $result = 0;
   if (strpos($_SERVER['SERVER_NAME'], 'rjmprogramming.com.au') !== false) {
   exec( "/usr/local/cpanel/3rdparty/bin/convert -density 300 " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".pdf " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".jpg"); //, null, $result ); // Thanks to https://stackoverflow.com/questions/8624886/pdf-to-jpg-conversion-using-php
   } else {
   exec( "/usr/local/bin/convert -density 300 " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".pdf " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".jpg"); //, null, $result ); // Thanks to https://stackoverflow.com/questions/8624886/pdf-to-jpg-conversion-using-php
   }
   if (strpos( $user_agent, 'Safari') !== false && strpos( $user_agent, 'Chrome') === false && strpos( $user_agent, 'OPR') === false && strpos( $user_agent, 'Firefox') === false && strpos( $user_agent, 'Opera') === false) {
   if (1 == 1) {
   $wobit="window.open('/" . $ourfname . ".pdf','_blank');";
   echo '<html><body onclick="' . $wobit . '" title="Click for PDF and/or scroll down to Sharing section" style="background:URL(' . 'data:image/jpeg;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.jpg')) . ');background-repeat:no-repeat;background-size:contain;"><img title="Click for PDF and/or scroll down to Sharing section" style=visibility:hidden; src="' . 'data:image/jpeg;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.jpg')) . '"></img></body></html>';
   } else {
   header('Content-Type: application/pdf');
   echo file_get_contents('./' . $ourfname . '.pdf');
   exec($safarisharehtmlbit);
   }
   } else {
   echo '<html><body><div style="overflow:auto;-webkit-overflow-scrolling:touch;height:100%;"><object style="width:100%;height:900px;" type="application/pdf" data="' . 'data:application/pdf;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.pdf')) . '">' . "\n" . '<embed style="width:100%;height:900px;" type="application/pdf" src="' .'data:application/pdf;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.pdf')) . '"></embed></object></div>' . $sharehtmlbit . '</body></html>'; 
   }
   exit;
} else if (isset($_GET['pdfimageplustext'])) {
   $w=0;
   $h=0;
   $outputpdf = new RPDF('P','pt');
   //if (isset($_GET['pdfrtext']) && isset($_GET['pdfgtext']) && isset($_GET['pdfbtext'])) {
   //$outputpdf->SetTextColor(urldecode($_GET['pdfrtext']), urldecode($_GET['pdfgtext']), urldecode($_GET['pdfbtext']));
   //}
   $outputpdf->SetTopMargin(0.0);
   //$outputpdf->AddPage('L');
   if (isset($_GET['pdfimage'])) {
    if (strpos(urldecode($_GET['pdfimage']), "data:image/") !== false && strpos(urldecode($_GET['pdfimage']), ";base64,") !== false) {
    $fname='./' . $ourfname . '.' . strtolower(explode(";", explode("data:image/", urldecode($_GET['pdfimage']))[1])[0]);
    file_put_contents($fname, base64_decode(str_replace(' ','+',explode(";base64,", urldecode($_GET['pdfimage']))[1])));
    list($w, $h) = getimagesize($fname);
    if ($w > $h) {
    $outputpdf->AddPage('L', 'A4');
    if ($w > 830) {
    $scale=floatval(830.0 / $w);
    $scalep=floatval($scale * 100.0);
    //$outputpdf->_out('q');
    //Scale(floatval($scalep), floatval($scalep));
    $newh=($h * (830.0 / $w));
    $outputpdf->Image($fname, 0, 0, 830, floatval($newh)); //, 33.78);
    //$outputpdf->_out('Q');
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    } else {
    $outputpdf->AddPage('P', 'A4');
    if ($h > 830) {
    $scale=floatval(830.0 / $h);
    $scalep=floatval($scale * 100.0);
    //Scale(floatval($scalep), floatval($scalep));
    $neww=($w * (830.0 / $h));
    $outputpdf->Image($fname, 0, 0, floatval($neww), 830); //, 33.78);
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    }
    } else if (strpos(urldecode($_GET['pdfimage']), "rjmprogramming.com.au/") !== false) {
    $fname="./" . explode(')',explode('&quot;',explode("rjmprogramming.com.au/", urldecode($_GET['pdfimage']))[1])[0])[0];
    //$outputpdf->Image("./" . explode("rjmprogramming.com.au/", urldecode($_GET['pdfimage']))[1], 0, 0); //, 33.78);
    list($w, $h) = getimagesize($fname);
    if ($w > $h) {
    $outputpdf->AddPage('L', 'A4');
    if ($w > 830) {
    $scale=floatval(830.0 / $w);
    $scalep=floatval($scale * 100.0);
    //$outputpdf->_out('q');
    //Scale(floatval($scalep), floatval($scalep));
    $newh=($h * (830.0 / $w));
    $outputpdf->Image($fname, 0, 0, 830, floatval($newh)); //, 33.78);
    //$outputpdf->_out('Q');
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    } else {
    $outputpdf->AddPage('P', 'A4');
    if ($h > 830) {
    $scale=floatval(830.0 / $h);
    $scalep=floatval($scale * 100.0);
    //Scale(floatval($scalep), floatval($scalep));
    $neww=($w * (830.0 / $h));
    $outputpdf->Image($fname, 0, 0, floatval($neww), 830); //, 33.78);
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    }
    } else {
     if (strpos(urldecode($_GET['pdfimage']), 'url(') !== false) {
    $fname=str_replace('&quot;','',explode(')',explode('url(',urldecode($_GET['pdfimage']))[1])[0]);
    } else {
    $fname=urldecode($_GET['pdfimage']);
    }
    //$outputpdf->Image(urldecode($_GET['pdfimage']), 0, 0); //, 33.78);
    list($w, $h) = getimagesize($fname);
    if ($w > $h) {
    $outputpdf->AddPage('L', 'A4');
    if ($w > 830) {
    $scale=floatval(830.0 / $w);
    $scalep=floatval($scale * 100.0);
    //$outputpdf->_out('q');
    //Scale(floatval($scalep), floatval($scalep));
    $newh=($h * (830.0 / $w));
    $outputpdf->Image($fname, 0, 0, 830, floatval($newh)); //, 33.78);
    //$outputpdf->_out('Q');
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    } else {
    $outputpdf->AddPage('P', 'A4');
    if ($h > 830) {
    $scale=floatval(830.0 / $h);
    $scalep=floatval($scale * 100.0);
    //Scale(floatval($scalep), floatval($scalep));
    $neww=($w * (830.0 / $h));
    $outputpdf->Image($fname, 0, 0, floatval($neww), 830); //, 33.78);
    } else {
    $outputpdf->Image($fname, 0, 0); //, 33.78);
    }
    }
    }
   } else {
    $outputpdf->AddPage('L','A4');
   }
   
   if (isset($_GET['pdftext1'])) {
   $texti=1;
   $ffy='Arial';
   $fst='B';
   $fsz=16;
   if (isset($_GET['pdffamily'])) {
     $ffy=str_replace('+',' ',urldecode($_GET['pdffamily']));
   }
   if (isset($_GET['pdffontstyle'])) {
     $fst=str_replace('N',' ',substr(strtoupper(str_replace('+',' ',urldecode($_GET['pdffontstyle']))) . ' ',0,1));
   }
   if (isset($_GET['pdffontsize'])) {
     if (strlen(trim(str_replace('+',' ',urldecode($_GET['pdffontsize'])))) > 0) {
       $fsz=str_replace('+',' ',urldecode($_GET['pdffontsize']));
     }
   }
   $ofsz=$fsz;
   $ofsz=$fst;
   while (isset($_GET['pdftext' . $texti]) && isset($_GET['pdfx' . $texti]) && isset($_GET['pdfy' . $texti])) {
     $exc="~";
     if (strpos(urldecode($_GET['pdfx' . $texti]), '.') !== false && strpos(urldecode($_GET['pdfy' . $texti]), '.') === false) {
       $fsz=explode('.', urldecode($_GET['pdfx' . $texti]))[1];
       if (substr('' . $fsz . '   ',4) == '0000') {
         $fst='B';
         $fsz=substr($fsz,4);
         if ($fsz == '') { $fsz=$ofsz;  }
       } else if (substr('' . $fsz . '   ',3) == '000') {
         $fst='U';
         $fsz=substr($fsz,3);
         if ($fsz == '') { $fsz=$ofsz;  }
       } else if (substr('' . $fsz . '  ',2) == '00') {
         $fst='I';
         $fsz=substr($fsz,2);
         if ($fsz == '') { $fsz=$ofsz;  }
       } else if (substr('' . $fsz . ' ',1) == '0') {
         $fst=' ';
         $fsz=substr($fsz,1);
         if ($fsz == '') { $fsz=$ofsz;  }
       } 
       $exc=".";
     }
     if (strlen(trim(urldecode($_GET['pdftext' . $texti]))) > 0) {
     //echo "yesooo";
     //exit;
       $outputpdf->SetFont($ffy,$fst,$fsz);
       $ourx=floatval($scale * floatval(explode($exc, urldecode($_GET['pdfx' . $texti]))[0]));
       $oury=floatval($scale * floatval(urldecode($_GET['pdfy' . $texti])));
       $stris=str_replace('^%&',' + ',str_replace('+',' ',str_replace('+++','^%&',urldecode($_GET['pdftext' . $texti]))));
   if (isset($_GET['pdfrtext']) && isset($_GET['pdfgtext']) && isset($_GET['pdfbtext'])) {
   $outputpdf->SetTextColor(urldecode($_GET['pdfrtext']), urldecode($_GET['pdfgtext']), urldecode($_GET['pdfbtext']));
   }
       if (isset($_GET['pdfdirectiontext'])) {
       $outputpdf->TextWithDirection($ourx,$oury,$stris,$_GET['pdfdirectiontext']);
       } else if (isset($_GET['pdfrotatetextdeg'])) {
       $outputpdf->TextWithRotation($ourx,$oury,$stris,$_GET['pdfrotatetextdeg'],0); 
       } 
     }
     $texti++;
     $fsz=$ofsz;
     $fst=$ofst;
   }
   }
   if (file_exists('./' . $ourfname . '.pdf')) {    unlink('./' . $ourfname . '.pdf');   }
   $outputpdf->Output("./" . $ourfname . ".pdf", "F");
   $result = 0;
   if (strpos($_SERVER['SERVER_NAME'], 'rjmprogramming.com.au') !== false) {
   exec( "/usr/local/cpanel/3rdparty/bin/convert -density 300 " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".pdf " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".jpg"); //, null, $result ); // Thanks to https://stackoverflow.com/questions/8624886/pdf-to-jpg-conversion-using-php
   } else {
   exec( "/usr/local/bin/convert -density 300 " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".pdf " . dirname(__FILE__) . DIRECTORY_SEPARATOR . $ourfname . ".jpg"); //, null, $result ); // Thanks to https://stackoverflow.com/questions/8624886/pdf-to-jpg-conversion-using-php
   }
   if (strpos( $user_agent, 'Safari') !== false && strpos( $user_agent, 'Chrome') === false && strpos( $user_agent, 'OPR') === false && strpos( $user_agent, 'Firefox') === false && strpos( $user_agent, 'Opera') === false) {
   if (1 == 1) {
   $wobit="window.open('/" . $ourfname . ".pdf','_blank');";
   echo '<html><body onclick="' . $wobit . '" title="Click for PDF and/or scroll down to Sharing section" style="background:URL(' . 'data:image/jpeg;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.jpg')) . ');background-repeat:no-repeat;background-size:contain;"><img title="Click for PDF and/or scroll down to Sharing section" style=visibility:hidden; onclick="' . $wobit . '" src="' . 'data:image/jpeg;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.jpg')) . '"></img>' . $sharehtmlbit . '</body></html>';
   } else {
   header('Content-Type: application/pdf');
   echo file_get_contents('./' . $ourfname . '.pdf');
   exec($safarisharehtmlbit);
   }
   } else {
   echo '<html><body><div style="overflow:auto;-webkit-overflow-scrolling:touch;height:100%;"><object style="width:100%;height:900px;" type="application/pdf" data="' . 'data:application/pdf;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.pdf')) . '">' . "\n" . '<embed style="width:100%;height:900px;" type="application/pdf" src="' .'data:application/pdf;base64,' . base64_encode(file_get_contents('./' . $ourfname . '.pdf')) . '"></embed></object></div>' . $sharehtmlbit . '</body></html>'; 
   }
   exit;
}

?>
