<?php namespace App\Controllers;

use CodeIgniter\Controller;
use Spipu\Html2Pdf\Html2Pdf;
use \App\Models\BlogModel;
use TCPDF;


//use CodeIgniter\I18n\Time;
//just testing 
class ProducePDF  extends BaseController
{




protected $myDate;
protected $myTime;




				 public function __construct() 
				    {
								parent::__construct();
						  $this->myTime = parent::getTime();
						$this->myDate= date("d/m/Y",$this->myTime); 	
					
			       }


   public function getPdf($slug)
   
   {
	   echo "needs working doing to get degment"; 
	   
	   echo $slug;
	   
	  
	  /***
	   * 
	   * strip_tags("Hello <b><i>world!</i></b>","<b>");
	   * above allows <br>
	   * 
	   * as of PHP 7.4.0 the line above can be written as:
       * echo strip_tags($text, ['p', 'a']);
	   * 
	   * 
	   * 
	   */
	  
	  
	  
	   
	   
	    
	    $handle= new BlogModel();
	   
	    $result= $handle->getArticle($slug);
	  $mytitle= $result["slug"];
	 $mystring= $result["article"];
	
	$mystring = $mytitle."<br><br>".$mystring;
	
	 $theImage = $result["image"];
	 $myStringStripTags= strip_tags($mystring, ['p', 'a', 'h4', 'h1','h3','h2']);
	 
	 echo "start of using TCPDF";
	 $html2pdf = new  TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
	//TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
	
	
	$html2pdf->setTitle("hello world");
	$html2pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$html2pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$html2pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$html2pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
$html2pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$html2pdf->setFontSubsetting(true);
$html2pdf->SetFont('dejavusans', '', 12, '', true);
	
	
	
	
	
	
	
	
	
	 $html2pdf-> AddPage('P',"A4");
	
	  $html2pdf->Image(base_url().'/blogImages/'.$theImage, '', 45, 50, 50, 'JPG', false);
	 
	 
	 
	 //above works but need space
	// $html2pdf->writeHTMLCell(0, 0, '', '', $mystring, 0, 1, 0, true, '', true);
	 $html2pdf->writeHTMLCell($w=0, $h=0, $x='', $y='100', $mystring, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
	  
    
    
	 
	 ob_end_clean();


$html2pdf->Output($mytitle.".pdf", 'D');




	 }  
      
    
	public function index()

	{






}
public function spam()
{




echo $this->myDate;





							
}											



}
  
