<?php

namespace App\Http\Controllers\UserAuth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Auth;
use App\Model\Sitesetting;
use Dompdf\Dompdf;
use Dompdf\Options;
use PDF;
class HomeController extends Controller {
	public function home()
	{
		$sitesetting=Sitesetting::first();
		return view('user.home')->with(['sitesetting'=>$sitesetting]);
	}
	public function test()
	{
		return view('user.pdf.questionpaper');
		$options = new Options();
        $options->setIsRemoteEnabled(true);
        $dompdf = new Dompdf($options);
		$dompdf->set_option('defaultFont', 'DejaVu Sans');
		
		$v = utf8_decode($v);
        $dompdf->loadHtml($v);

        $dompdf->setPaper('A4', 'portrait');

        $dompdf->render();
		$x          = 250;
        $y          = 800;
        $text       = "All The best";  
		$font       = $dompdf->getFontMetrics()->get_font('Source Sans Pro', 'sans-serif');  
        $size       = 10;    
        $color      = array(0,0,0);
        $word_space = 0.0;
        $char_space = 0.0;
        $angle      = 0.0;
		$dompdf->getCanvas()->page_text(
          $x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle
        );
        $canvas = $dompdf->get_canvas();
		

        $output = $dompdf->output();
        $filename=time();
		file_put_contents('public/pdf/'.$filename.'.pdf', $output);
		
			$response['pdffile']=url('/public/pdf/'.$filename.'.pdf');
			$response['result'] = '1';
		
		return view('user.pdf.paperlink')->with(['paperlink'=>$response['pdffile']]);
	}
	public function test2()
  {
    $pdf = \PDF::loadView('user.pdf.questionpaper');
    return $pdf->stream('user.pdf');
  }
}
