<?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);
}

}

$factor=1;
$lastrepeat="";
$repeats=0;
$newd=null;
$mewd=null;
$ofsz="";
$ofst="";
$orot="";
$odir="";
$user_agent = $_SERVER['HTTP_USER_AGENT']; 
$ffnos="Text <input style=display:inline-block;width:40px; type=number value=1 id=tnum min=1></input> from now on Colour Size Direction Rotation Style Family ideas ... <br><input onblur=fromnowon(this); style=display:inline-block; type=color id=tcol value=#000000></input>&nbsp<input onblur=fromnowon(this); style=display:inline-block;width:40px; type=number step=1 min=0 id=tsiz value=16></input>px&nbsp;<select onchange=fromnowon(this); id=tdir><option value=R>Right</option><option value=L>Left</option><option value=D>Down</option><option value=U>Up</option></select>&nbsp<input onblur=fromnowon(this); style=display:inline-block; type=number step=1 min=0 max=359 id=trot value=0></input>&deg;&nbsp;<select onchange=fromnowon(this); id=tsty><option value=>Bold</option><option value=N>Normal</option><option value=I>Italic</option><option value=U>Underline</option></select>&nbsp;<select onchange=fromnowon(this); id=tfam><option value=Arial>Arial</option><option value=Courier>Coiurier</option><option value=Helvetica>Helvetica</option><option value=Times>Times</option><option value=Symbol>Symbol</option><option value=ZapfDingbats>ZapfDingbats</option></select>&nbsp&nbsp;<input style=background-color:yellow; type=button onclick='showingc=showing; event.stopPropagation(); fromnowon(this);' id=tbut value='Apply From Now On ...'></input>";

function ffs($insuf) {
   global $ffy, $fst, $fsz, $ofsz, $ofst;
   if (isset($_POST['pdffamily' . $insuf])) {
     $ffy=str_replace('+',' ',urldecode($_POST['pdffamily' . $insuf]));
   }
   if (isset($_POST['pdffontstyle' . $insuf])) {
     $fst=str_replace('N',' ',substr(strtoupper(str_replace('+',' ',urldecode($_POST['pdffontstyle' . $insuf]))) . ' ',0,1));
     if ($insuf != '') { $ofst=$fst; }
   }
   if (isset($_POST['pdffontsize' . $insuf])) {
     if (strlen(trim(str_replace('+',' ',urldecode($_POST['pdffontsize' . $insuf])))) > 0) {
       $fsz=str_replace('+',' ',urldecode($_POST['pdffontsize' . $insuf]));
       if ($insuf != '') { $ofsz=$fsz; }
     }
   }
   if ($ofsz == "") { $ofsz=$fsz; }
   if ($ofst == "") { $ofst=$fst; }
}

function gffs($insuf) {
   global $ffy, $fst, $fsz, $ofsz, $ofst;
   if (isset($_GET['pdffamily' . $insuf])) {
     $ffy=str_replace('+',' ',urldecode($_GET['pdffamily' . $insuf]));
   }
   if (isset($_GET['pdffontstyle' . $insuf])) {
     $fst=str_replace('N',' ',substr(strtoupper(str_replace('+',' ',urldecode($_GET['pdffontstyle' . $insuf]))) . ' ',0,1));
     if ($insuf != '') { $ofst=$fst; }
   }
   if (isset($_GET['pdffontsize' . $insuf])) {
     if (strlen(trim(str_replace('+',' ',urldecode($_GET['pdffontsize' . $insuf])))) > 0) {
       $fsz=str_replace('+',' ',urldecode($_GET['pdffontsize' . $insuf]));
       if ($insuf != '') { $ofsz=$fsz; }
     }
   }
   if ($ofsz == "") { $ofsz=$fsz; }
   if ($ofst == "") { $ofst=$fst; }
}

function yoururldecode($inmd) {
  return urldecode($inmd);
}

function nuance($zrepeats,$inoth,$inrs,$negplus,$inpal,$outpal) {
  global $newd, $repeats, $lastrepeat, $factor;
    //echo "zrepeats=". $zrepeats . "and repeats=" . $repeats;
    //exit;
  if ($repeats < 0) {
    $lastrepeat=$inpal;
    //$repeats=-$repeats;
  } else if ($repeats > 0) {
    $inpal=$lastrepeat;
    $repeats--;
  }
  $intd='D';
  $outrs="";
  //$factor=$negplus;
  $five=5;
  $inpcols=explode(':', $outpal);
  $justdatelen=(-3 + strlen($inpcols[0]));
  if ($inoth == strtoupper($inoth) && trim($inrs) == '') { return $outpal; }
  if ($inoth == 'DATE' . strtolower(substr($inoth,0,4)) && trim($inrs) == '') { return substr($outpal,0,$justdatelen); }
  if ($inoth == 'date' . strtoupper(substr($inoth,0,4)) && trim($inrs) == '') { return substr($outpal,$justdatelen); }
  if (trim($inrs) != '' || strpos(strtoupper($inoth), 'DATE') !== false) {
    $outrs=explode(" ", $inrs)[0];
    if (trim($outrs) != '' || strpos(strtoupper($inoth), 'DATE') !== false) {
      if (str_replace('-','',str_replace('.','',str_replace('=','',str_replace('+','',str_replace('0','',str_replace('1','',str_replace('2','',str_replace('3','',str_replace('4','',str_replace('5','',str_replace('6','',str_replace('7','',str_replace('8','',str_replace('9','',trim($outrs))))))))))))))) == '') {
        if (trim($outrs) != '') { $factor*=str_replace('-','',str_replace('+','',$outrs)); }
        if (strpos($inoth, 'DATE') !== false) {
          if (substr($inoth, $five) == strtolower(substr($inoth, $five, 1)) . strtoupper(substr($inoth, (1 + $five)))) {
            $intd='Y';
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 1)) . strtolower(substr($inoth, (1 + $five), 1)) . strtoupper(substr($inoth, (2 + $five)))) {
            $intd='M';
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 2)) . strtolower(substr($inoth, (2 + $five), 1)) . strtoupper(substr($inoth, (3 + $five)))) {
            $intd='D';
          }
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('P' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('P' . $negplus . $intd));
          }
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
    $repeats=-$zrepeats;
          }
          return substr($outpal,0,$justdatelen); 
        } else if (strpos($inoth, 'date') !== false) {
          $intd='H';
          if (substr($inoth, $five) == strtolower(substr($inoth, $five, 1)) . strtoupper(substr($inoth, (1 + $five)))) {
            $intd='H';
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 1)) . strtolower(substr($inoth, (1 + $five), 1)) . strtoupper(substr($inoth, (2 + $five)))) {
            $intd='M';
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 2)) . strtolower(substr($inoth, (2 + $five), 1)) . strtoupper(substr($inoth, (3 + $five)))) {
            $intd='S';
          }
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('PT' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('PT' . $negplus . $intd));
          }
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
    $repeats=-$zrepeats;
          }
          return substr($outpal,$justdatelen); 
        } else {
          $five=0;
          $intd='D';
  //echo "InoTH=" . $inoth . " and factor=" . $factor;
  //exit;
          if (substr($inoth, $five) == strtolower(substr($inoth, $five, 1)) . strtoupper(substr($inoth, (1 + $five)))) {
            $intd='Y';
            //echo 'P' . $factor . $intd;
            //exit;
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('P' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('P' . $negplus . $intd));
          }
           } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
    $repeats=-$zrepeats;
          }
           return $outpal; 
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 1)) . strtolower(substr($inoth, (1 + $five), 1)) . strtoupper(substr($inoth, (2 + $five)))) {
            $intd='M';
            //echo 'P' . $factor . $intd;
            //exit;
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('P' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('P' . $negplus . $intd));
          }
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
    $repeats=-$zrepeats;
          }
            return $outpal; 
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 2)) . strtolower(substr($inoth, (2 + $five), 1)) . strtoupper(substr($inoth, (3 + $five)))) {
            $intd='D';
            //echo 'P' . $negplus . $intd;
            //exit;
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('P' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('P' . $negplus . $intd));
          }
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
    $repeats=-$zrepeats;
          }
            return $outpal; 
          }
          $five=5;
          if (substr($inoth, $five) == strtolower(substr($inoth, $five, 1)) . strtoupper(substr($inoth, (1 + $five)))) {
            $intd='H';
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('PT' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('PT' . $negplus . $intd));
          }
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
    $repeats=-$zrepeats;
          }
            return $outpal; 
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 1)) . strtolower(substr($inoth, (1 + $five), 1)) . strtoupper(substr($inoth, (2 + $five)))) {
            $intd='M';
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('PT' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('PT' . $negplus . $intd));
          }
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
    $repeats=-$zrepeats;
          }
            return $outpal; 
          } else if (substr($inoth, $five) == strtoupper(substr($inoth, $five, 2)) . strtolower(substr($inoth, (2 + $five), 1)) . strtoupper(substr($inoth, (3 + $five)))) {
            $intd='S';
          if ($zrepeats >= 0) {
          if (strpos(('' . $negplus), '-') !== false) {
          $newd->sub(new DateInterval('PT' . str_replace('-','','' . $negplus) . $intd));
          } else {
          $newd->add(new DateInterval('PT' . $negplus . $intd));
          }
          } else if ($zrepeats < 0) {
    //$lastrepeat=$inpal;
    $repeats=-$zrepeats;
          }
            return $outpal; 
          }
          return $outpal; 
        }
      }      
    }
  }
  return $outpal;
}

function oururldecode($inmd) {
  global $newd, $repeats, $lastrepeat, $factor;
  if (!$newd || strpos(strtoupper('~' . urldecode($inmd)), '~DATE') === false) { 
    if (strpos(str_replace('+',' ',urldecode($inmd)), ' x ') !== false) {
      $inmd=urlencode(explode(' x ', str_replace('+',' ',urldecode($inmd)))[0]);
    } else if (strpos(str_replace('+',' ',urldecode($inmd)), ' * ') !== false) {
      $inmd=urlencode(explode(' * ', str_replace('+',' ',urldecode($inmd)))[0]);
    }
    return urldecode($inmd); 
  }
  $dateadd=0;
  $xrepeats=0;
  $factor=1;
  $halfchar="_";
  $retstr="";
        //echo "inmd=" . str_replace('+',' ',urldecode($inmd)); // . " xRePeats=" . explode(' x ', str_replace('+',' ',urldecode($inmd)))[1] . ' ';
        //exit;
  if ($repeats == 0 || strpos(str_replace('+',' ',urldecode($inmd)), ' x ') !== false || strpos(str_replace('+',' ',urldecode($inmd)), ' * ') !== false) {
    if (strpos(str_replace('+',' ',urldecode($inmd)), ' x ') !== false) {
      $xrepeats-=floatval(explode(' x ', str_replace('+',' ',urldecode($inmd)))[1]);
      $xrepeats--;
      $inmd=urlencode(explode(' x ', str_replace('+',' ',urldecode($inmd)))[0]);
    } else if (strpos(str_replace('+',' ',urldecode($inmd)), ' * ') !== false) {
      $xrepeats-=floatval(explode(' * ', str_replace('+',' ',urldecode($inmd)))[1]);
      $xrepeats--;
      $inmd=urlencode(explode(' * ', str_replace('+',' ',urldecode($inmd)))[0]);
    }
  } 
  if ($repeats > 0) {
      $inmd=$lastrepeat;
      $xrepeats=$repeats;
  }
  if (strpos(strtoupper('~' . urldecode($inmd)), '~DATE-') !== false) {
    $halfchar="-";
    $factor=-1;
  }
  if (strpos(strtoupper('~' . urldecode($inmd)), '~DATE+') !== false) {
    $halfchar="+";
  }
  if (strpos(strtoupper('~' . urldecode($inmd)), '~DATE ') !== false) {
    $halfchar=" ";
  }
  if (strpos(str_replace('+',' ',urldecode($inmd)), '--') !== false) {
    $factor=-1;
  }
  if (strpos(str_replace('+',' ',urldecode($inmd)), '  ') !== false) {
    $factor=1;
  }
  if (strpos(str_replace('+',' ',urldecode($inmd)), '-=') !== false) {
    $factor=-1;
    //echo explode(' ',explode(';',explode('-=', str_replace('+',' ',urldecode($inmd)))[1])[0])[0];
    //exit;
    $factor*=floatval(explode(' ',explode(';',explode('-=', str_replace('+',' ',urldecode($inmd)))[1])[0])[0]);
  }
  if (strpos(str_replace('+',' ',urldecode($inmd)), ' =') !== false) {
    $factor*=floatval(explode(' ',explode(';',explode(' =', str_replace('+',' ',urldecode($inmd)))[1])[0])[0]);
  }
  if (strpos(strtoupper('~' . urldecode($inmd)), '~DATE' . $halfchar) !== false) {
    //echo "factor=" . $factor;
    //exit;
    if ($xrepeats < 0) {
      $repeats=$xrepeats;
      $lastrepeat=$inmd;
    } else if ($repeats > 0) {
      $inmd=$lastrepeat;
    }
    $oth=explode(' ',explode('-',explode('+',explode('DATE' . $halfchar, strtoupper(urldecode($inmd)))[1])[0])[0])[0];
    $ucoth=substr(str_replace($halfchar,'_',str_replace('+',' ',urldecode($inmd))), 0, (5 + strlen($oth)));
    $rsoth=trim(substr(str_replace('+',' ',urldecode($inmd)), strlen($ucoth)));
    switch ($oth) {
      case 'ATOM':
        //echo "xRepeats=" . $xrepeats . ' ';
        //exit;
        //echo $newd->format(DateTime::ATOM);
        //exit;
        //($ucoth,$rsoth,$factor,$newd);
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::ATOM)); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0];
        $xx=str_replace('DATE' . $halfchar . 'ATOM',substr($newd->format(DateTime::ATOM),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        //echo "zero=" . $zero . " retstr=" . $retstr . " xx=" . $xx . " and inmd=" . strtoupper(urldecode($inmd)) . " vs " . 'DATE' . $halfchar . 'ATOM' . " and =" . $newd->format(DateTime::ATOM);
        //exit;
        return str_replace('DATE' . $halfchar . 'ATOM',substr($newd->format(DateTime::ATOM),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'COOKIE':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::COOKIE)); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0];
        return str_replace('DATE' . $halfchar . 'COOKIE',substr($newd->format(DateTime::DATE_COOKIE),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'ISO8601':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::ISO8601)); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0];
        return str_replace('DATE' . $halfchar . 'ISO8601',substr($newd->format(DateTime::DATE_ISO8601),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RFC822':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RFC822)); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0];
        return str_replace('DATE' . $halfchar . 'RFC822',substr($newd->format(DateTime::DATE_RFC822),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RFC850':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RFC850)); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0];
        return str_replace('DATE' . $halfchar . 'RFC850',substr($newd->format(DateTime::DATE_RFC850),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RFC1036':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RFC1036)); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0];
        return str_replace('DATE' . $halfchar . 'RFC1036',substr($newd->format(DateTime::DATE_RFC1036),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RFC1123':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RFC1123)); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0];
        return str_replace('DATE' . $halfchar . 'RFC1123',substr($newd->format(DateTime::DATE_RFC1123),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RFC2822':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RFC2822)); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0];
        return str_replace('DATE' . $halfchar . 'RFC2822',substr($newd->format(DateTime::DATE_RFC2822),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RFC3339':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RFC3339)); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0];
        return str_replace('DATE' . $halfchar . 'RFC3339',substr($newd->format(DateTime::DATE_RFC3339),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'RSS':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::RSS)); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0];
        return str_replace('DATE' . $halfchar . 'RSS',substr($newd->format(DateTime::DATE_RSS),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      case 'W3C':
    $retstr=nuance($xrepeats,$ucoth,$rsoth,$factor,str_replace('+',' ',urldecode($inmd)),$newd->format(DateTime::W3C)); //,$newd);
    $zero=0;
    if (strpos($retstr, ':') !== false && strlen(str_replace('+',' ',urldecode($inmd))) != strlen($retstr)) {
      $zero=(0 - strlen($retstr));
    }
        $inmd=substr(str_replace('+',' ',urldecode($inmd)),0,5) . explode('+',explode(' ',substr(str_replace('+',' ',urldecode($inmd)),5))[0])[0];
        return str_replace('DATE_W3C',substr($newd->format(DateTime::DATE_W3C),$zero,strlen($retstr)),strtoupper(urldecode($inmd)));
        break;
      default:
        break;
    }
  }
  return urldecode($inmd);
}

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><head><title>Image and Text Nodes PDF Creator - RJM Programming - August, 2022</title></head>
<body style='background:" . urldecode($_GET['justiurl']) . ";background-repeat:no-repeat;'>
</body>
</html>";
   exit;
} else if (1 == 7 && isset($_POST['justiurl'])) {
   echo "<html><head><title>Image and Text Nodes PDF Creator - RJM Programming - August, 2022</title></head>
<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><title>Image and Text Nodes PDF Creator - RJM Programming - August, 2022</title>
<style>

 .custom-alert {
  display: inline-block;
  /* visibility: visible; */
  background-color: rgba(102,102,102,0.8);
  color: #fff;
  text-align: center;
  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;
 }

 .custom-prompt {
  display: inline-block;
  /* visibility: visible; */
  background-color: rgba(202,202,202,0.8);
  color: #fff;
  text-align: center;
  margin: 5% auto;
  padding: 12px 28px;
  opacity: 0.9;
  z-index: 200;
  -webkit-animation: wglow 1s linear infinite alternate;
  -moz-animation: wglow 1s linear infinite alternate;
  animation: wglow 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;
  }
 }


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

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

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

var datauri='';
var coordn=1;
var x=-1, y=-1;
var startrecording=false;
var ontox='';
var repeats=0, lastans='';
var nofiddling=false;
var showing=false;
var showingc=false;
var ffnos=\"" . $ffnos . "\";
var cpone=\"" . $ffnos . "\";
var cmds=[];
var tempcmd=\" document.getElementById('coords').innerHTML+='<input type=hidden name=xxx value=zzz></input>'; \"; 

function getr(incis) {
  return '' + hexdec(incis.replace('#','').substring(0,2));
}

function getg(incis) {
  return '' + hexdec(incis.replace('#','').substring(2).substring(0,2));
}

function getb(incis) {
  return '' + hexdec(incis.replace('#','').substring(4).substring(0,2));
}

 function hexdec(hexString) {  // thanks to https://locutus.io/php/math/hexdec/
  //  discuss at: https://locutus.io/php/hexdec/
  // original by: Philippe Baumann
  //   example 1: hexdec('that')
  //   returns 1: 10
  //   example 2: hexdec('a0')
  //   returns 2: 160

  hexString = (hexString + '').replace(/[^a-f0-9]/gi, '');
  return parseInt(hexString, 16);
 }

 function hex2dec(couleur, inopac) {
    var dolR = couleur.toLowerCase().replace('#','').substring(0,2);
    var dolrouge = hexdec(dolR);
    var dolV = couleur.toLowerCase().replace('#','').replace(dolR,'').substring(0,2);
    var dolvert = hexdec(dolV);
    var dolB = couleur.toLowerCase().replace('#','').replace(dolR,'').replace(dolV,'').substring(0,2);
    var dolbleu = hexdec(dolB);
    if (('' + inopac).replace('1.0','') != '') {
      return 'rgba(' + dolrouge + ',' + dolvert + ',' + dolbleu + ',' + inopac + ')';
    } else if (1 == 2) {
      return couleur.toLowerCase();
    } else {
      return 'rgb(' + dolrouge + ',' + dolvert + ',' + dolbleu + ')';
    }
 }

function fromnowon(ovis) {
   var jdi=0;
   var idi='' + document.getElementById('tnum').value;
   var newcmd='', newsuff='', newpref='';
   if (ovis.id == 'tnum') {
    jdi=jdi;
   } else if (ovis.id == 'tbut') {
    for (jdi=0; jdi<cmds.length; jdi++) {
      newcmd=cmds[jdi];
      if (newcmd.indexOf('' + idi + ' value=') == -1) {
        newsuff=' value=' + newcmd.split(' value=')[1];
        newpref=cmds[jdi].split('0')[0].split('1')[0].split('2')[0].split('3')[0].split('4')[0].split('5')[0].split('6')[0].split('7')[0].split('8')[0].split('9')[0];
        cmds[jdi]=newpref + idi + newsuff;
        newcmd=cmds[jdi];
      }
      //alert(newcmd);
      eval(newcmd);
  showing=false;
  showingc=false;
  document.getElementById('custom-prompt-1').style.display='none';
    }
    cmds=[];
   } else if (ovis.id == 'tcol') {
    cmds.push(tempcmd.replace('xxx', 'pdfrtext' + idi).replace('zzz', getr(ovis.value.trim())));
    cmds.push(tempcmd.replace('xxx', 'pdfgtext' + idi).replace('zzz', getg(ovis.value.trim())));
    cmds.push(tempcmd.replace('xxx', 'pdfbtext' + idi).replace('zzz', getb(ovis.value.trim())));
   } else if (ovis.id == 'tsiz') {
    cmds.push(tempcmd.replace('xxx', 'pdffontsize' + idi).replace('zzz', ovis.value.trim()));
   } else if (ovis.id == 'tsty') {
    cmds.push(tempcmd.replace('xxx', 'pdffontstyle' + idi).replace('zzz', ovis.value.trim()));
   } else if (ovis.id == 'trot') {
    cmds.push(tempcmd.replace('xxx', 'pdfrotatetextdeg' + idi).replace('zzz', ovis.value.trim()));
   } else if (ovis.id == 'tdir') {
    cmds.push(tempcmd.replace('xxx', 'pdfdirectiontext' + idi).replace('zzz', ovis.value.trim()));
   } else if (ovis.id == 'tfam') {
    cmds.push(tempcmd.replace('xxx', 'pdffamily' + idi).replace('zzz', ovis.value.trim()));
   }
}

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>';
   //alert('x=' + x + ' andy=' + y + ' and text=' + withwhat);
      coordn++;
      document.getElementById('tnum').value='' + coordn;
      ontox='';
      startrecording=false; 
    } //else {
       //alert('oops');
    //}
  }
}

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=outans.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=\"N\"></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='N';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"N\"></input>';
          }
        } else {
        outans=outans.replace(arris[iarris] + ';', '');
          zeroes='0';
        }
            break;
          case 'n':
        if (outans.indexOf(arris[iarris] + ';;') != -1) {
        outans=outans.replace(arris[iarris] + ';;', '');
          if (document.getElementById('pdffontstyle')) {
          document.getElementById('pdffontstyle').value='N';
          } else {
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdffontstyle name=pdffontstyle value=\"N\"></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; }
  if (repeats > 0) { repeats--; if (repeats == 0) { lastans=''; }  }
  return outans;
}

function askaway() {
  var ans=' ';
  if (startrecording && !showingc) {
  if (repeats > 0) {
  ans=lastans;
  if (ans == null) { ans=''; }
  if (analyze(ans).trim() == '') { startrecording=false; if (1 == 11) {  alert(document.getElementById('coords').innerHTML);  } document.getElementById('myform').submit();  } else { addtoform(ans); setTimeout(askaway, 5000);   }
  } else {
  repeats=0;
  lastans='';
  ans=prompt('Enter with nothing to proceed.  Else enter text number ' + coordn + ' to place where last click was made.  Can use a suffix such as x 5 to repeat value on the 4 clicks to follow.  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=''; }
  var rarris=ans.replace(' * ',' x ').split(' x 1');
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 2');  } 
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 3');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 4');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 5');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 6');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 7');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 8');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 9');  }
  if (rarris.length == 1) {  rarris=ans.replace(' * ',' x ').split(' x 0');  }
  if (rarris.length > 1) { repeats=eval(0 + eval('' + ans.replace(' * ',' x ').split(' x ')[1])); lastans=ans.replace(' * ',' x ').split(' x ')[0];   } else if (1 == 3) { lastans=''; }
  if (analyze(ans).trim() == '') { startrecording=false; if (1 == 11) {  alert(document.getElementById('coords').innerHTML);  } 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();
       if (!showingc) {
       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.   Can use a suffix such as x 5 to repeat value on the 4 clicks to follow.  As far as dates go consult https://www.w3schools.com/php/func_date_date_format.asp DATE_ATOM type entries where DATE_ followed by ymd lowercase character correspondence in second part means change just date via that ymd means whereas date_ followed by hms lowercase character correspondence in second part means change time via that hms means whereas uppercase second part preceeded by ymd lowercase character in first part means change datetime via that ymd means whereas datE_ followed by hms lowercase character correspondence in second part means change datetime via that hms means.  Incrementing scale can be defined via ++ or -- or +=2 or -=4 types of strings before the x 5 repeat definitions.'; //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.  There are also other glowing <i>from now on</i> ways to change the text look.</div>\";
  document.body.innerHTML+=\"<div onclick='showingc=showing; event.stopPropagation();' id=custom-prompt-1 class=custom-prompt style='position:fixed; left: 70%; transform: translate(-70%, -10%); top:10%; display: none;'>\" + cpone +  \"</div>\";
  setTimeout(hideIt, 10000);
  setTimeout(showPromptIt, 5000);
 }

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

 function showPromptIt() {
  showing=true;
  showingc=false;
  document.getElementById('custom-prompt-1').style.display='block';
  if (cpone == '') {
  cpone=document.getElementById('custom-prompt-1').innerHTML;
  }
  setTimeout(hidePromptIt, 20000);
 }

 function hidePromptIt() {
  showing=false;
  showingc=false;
  document.getElementById('custom-prompt-1').style.display='none';
  setTimeout(showPromptIt, 10000);
 }

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>';
          cpone=cpone.replace(' value=#000000', ' value=#' + hases[1].split('(')[1].split(',')[0].toString(16) + hases[1].split('(')[1].split(',')[1].toString(16) + hases[1].replace(')',',').split('(')[1].split(',')[2].toString(16));
          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>'; 
          cpone=cpone.replace(' value=16', ' value=' + szc);
        }
        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>'; 
          cpone=cpone.replace(' value=0', ' value=' + trc);
        }
        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();
          cpone=cpone.replace(' id=tsty>', ' id=tsty><option value=>Normal</option>');
        }
        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();
          cpone=cpone.replace(' id=tsty>', ' id=tsty><option value=I>Italic</option>');
        }
        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();
          cpone=cpone.replace(' id=tsty>', ' id=tsty><option value=U>Underline</option>');
        }
        if (hases[1].indexOf('R') != -1) { 
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfdirectiontext name=pdfdirectiontext value=R></input>'; 
          cpone=cpone.replace(' id=tdir>', ' id=tdir><option value=Right>Right</option>');
        } 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>'; 
          cpone=cpone.replace(' id=tdir>', ' id=tdir><option value=U>Up</option>');
        } else if (hases[1].indexOf('D') != -1) { 
          document.getElementById('coords').innerHTML+='<input type=hidden id=pdfdirectiontext name=pdfdirectiontext value=D></input>'; 
          cpone=cpone.replace(' id=tdir>', ' id=tdir><option value=D>Down</option>');
        }
      }
      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 onload=\"  document.getElementById('mytzn').value='' + Intl.DateTimeFormat().resolvedOptions().timeZone;  \">
<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> 
<input type=hidden id=mytzn name=mytzn value='UTC'></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'])) {
   if (isset($_POST['mytzn'])) {
    if (('' . urldecode($_POST['mytzn'])) != '') {
     date_default_timezone_set(urldecode($_POST['mytzn']));
    }
   }
   $newd=new DateTime(); //date_create('');
   $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 (1 == 1) {
   ffs('');
   } else {
   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])) {
   ffs('' . $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,trim($fst),$fsz);
       $ourx=floatval($scale * floatval(explode($exc, urldecode($_POST['pdfx' . $texti]))[0]));
       $oury=floatval($scale * floatval(urldecode($_POST['pdfy' . $texti])));
       if ($repeats == 1) {
       $stris=str_replace('^%&',' + ',str_replace('+',' ',str_replace('+++','^%&',   oururldecode($_POST['pdftext' . $texti]))));
       $newd=new DateTime();
       } else {
       $stris=str_replace('^%&',' + ',str_replace('+',' ',str_replace('+++','^%&',   oururldecode($_POST['pdftext' . $texti]))));
       }
   if (isset($_POST['pdfrtext' . $texti]) && isset($_POST['pdfgtext' . $texti]) && isset($_POST['pdfbtext' . $texti])) {
   $outputpdf->SetTextColor(urldecode($_POST['pdfrtext' . $texti]), urldecode($_POST['pdfgtext' . $texti]), urldecode($_POST['pdfbtext' . $texti]));
   if (isset($_POST['pdfrtext'])) { // because means "from here on"
     $_POST['pdfrtext']=$_POST['pdfrtext' . $texti];
     $_POST['pdfgtext']=$_POST['pdfgtext' . $texti];
     $_POST['pdfbtext']=$_POST['pdfbtext' . $texti];
   }
   } else 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' . $texti])) {
    //file_put_contents('xxx.xxx',$_POST['pdfdirectiontext' . $texti]);
       if (('' . urldecode($_POST['pdfdirectiontext' . $texti])) == '') {
    //file_put_contents('xx.xxx',$_POST['pdfdirectiontext' . $texti]);
       $outputpdf->Text($ourx,$oury,$stris); 
       if (isset($_POST['pdfdirectiontext'])) {
         $_POST['pdfdirectiontext']="L"; // because means "from here on"
       } 
       } else {
    //file_put_contents('xx.xx',$_POST['pdfdirectiontext' . $texti]);
       $outputpdf->TextWithDirection($ourx,$oury,$stris,$_POST['pdfdirectiontext' . $texti]);
       if (isset($_POST['pdfdirectiontext'])) {
         $_POST['pdfdirectiontext']=$_POST['pdfdirectiontext' . $texti]; // because means "from here on"
       } else {
         $odir=$_POST['pdfdirectiontext' . $texti];
       }
       }
       } else if (isset($_POST['pdfrotatetextdeg' . $texti])) {
       if (('' . urldecode($_POST['pdfrotatetextdeg' . $texti])) == '') {
       $outputpdf->Text($ourx,$oury,$stris); 
       if (isset($_POST['pdfrotatetextdeg'])) {
         $_POST['pdfrotatetextdeg']="0"; // because means "from here on"
       }
       } else {
       $outputpdf->TextWithRotation($ourx,$oury,$stris,$_POST['pdfrotatetextdeg' . $texti],0); 
       if (isset($_POST['pdfrotatetextdeg'])) {
         $_POST['pdfrotatetextdeg']=$_POST['pdfrotatetextdeg' . $texti]; // bdecause means "from here on"
       } else {
         $orot=$_POST['pdfrotatetextdeg' . $texti];
       }
       }
       } else if ($odir != "") {
    //file_put_contents('xxxx.xx',$odir . ' for ' . $texti);
       $outputpdf->TextWithDirection($ourx,$oury,$stris,$odir);
       } else if (isset($_POST['pdfdirectiontext'])) {
    //file_put_contents('xxxxx.xx',$_POST['pdfdirectiontext'] . ' For ' . $texti);
       $outputpdf->TextWithDirection($ourx,$oury,$stris,$_POST['pdfdirectiontext']);
       } else if ($orot != "") {
       $outputpdf->TextWithRotation($ourx,$oury,$stris,$orot,0); 
       } 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,trim($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' . $texti]) && isset($_GET['pdfgtext' . $texti]) && isset($_GET['pdfbtext' . $texti])) {
   $outputpdf->SetTextColor(urldecode($_GET['pdfrtext' . $texti]), urldecode($_GET['pdfgtext' . $texti]), urldecode($_GET['pdfbtext' . $texti]));
   if (isset($_GET['pdfrtext'])) { // because means "from here on"
     $_GET['pdfrtext']=$_GET['pdfrtext' . $texti];
     $_GET['pdfgtext']=$_GET['pdfgtext' . $texti];
     $_GET['pdfbtext']=$_GET['pdfbtext' . $texti];
   }
   } else 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' . $texti])) {
       if (strlen($_GET['pdfdirectiontext' . $texti]) == 0) {
       $outputpdf->Text($ourx,$oury,$stris); 
       if (isset($_GET['pdfdirectiontext'])) {
         $_GET['pdfdirectiontext']="L"; // because means "from here on"
       } 
       } else {
       $outputpdf->TextWithDirection($ourx,$oury,$stris,$_GET['pdfdirectiontext' . $texti]);
       if (isset($_GET['pdfdirectiontext'])) {
         $_GET['pdfdirectiontext']=$_GET['pdfdirectiontext' . $texti]; // because means "from here on"
       }
       }
       } else if (isset($_GET['pdfrotatetextdeg' . $texti])) {
       if (strlen($_GET['pdfrotatetextdeg' . $texti]) == 0) {
       $outputpdf->Text($ourx,$oury,$stris); 
       if (isset($_GET['pdfrotatetextdeg'])) {
         $_GET['pdfrotatetextdeg']="0"; // because means "from here on"
       }
       } else {
       $outputpdf->TextWithRotation($ourx,$oury,$stris,$_GET['pdfrotatetextdeg' . $texti],0); 
       if (isset($_GET['pdfrotatetextdeg'])) {
         $_GET['pdfrotatetextdeg']=$_GET['pdfrotatetextdeg' . $texti]; // bdecause means "from here on"
       }
       }
       } else if (isset($_GET['pdfdirectiontext'])) {
       $outputpdf->TextWithDirection($ourx,$oury,$stris,$_GET['pdfdirectiontext']);
       } else if (isset($_GET['pdfrotatetextdeg'])) {
       $outputpdf->TextWithRotation($ourx,$oury,$stris,$_GET['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; 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;
}

?>
