<?php
defined('BASEPATH') or exit('No direct script access allowed');
// panggil autoload dompdf nya
use Dompdf\Dompdf;
use Dompdf\Options;

class Pdfgenerator
{
    // Bukti Pencairan
    public function generate_bukti_terima_pencairan($html, $file_pdf, $paper, $lokasi_file, $orientation, $stream = TRUE)
    {
        $options = new Options();
        $options->set('isRemoteEnabled', TRUE);
        $dompdf = new Dompdf($options);
        $dompdf->loadHtml($html);
        $dompdf->setPaper($paper, $orientation);
        $dompdf->render();
        $output = $dompdf->output();
        file_put_contents('' . $lokasi_file . '' . $file_pdf . '.pdf', $output);
    }
    // Bukti Omset Pencairan
    public function generate_bukti_omset_pencairan($html, $file_pdf, $paper, $lokasi_file, $orientation, $stream = TRUE)
    {
        $options = new Options();
        $options->set('isRemoteEnabled', TRUE);
        $dompdf = new Dompdf($options);
        $dompdf->loadHtml($html);
        $dompdf->setPaper($paper, $orientation);
        $dompdf->render();
        $output = $dompdf->output();
        file_put_contents('' . $lokasi_file . '' . $file_pdf . '.pdf', $output);
    }
    // Bukti Pembayaran tanda terima
    public function generate_cetakTandaTerima($html, $file_pdf, $paper, $lokasi_file, $orientation, $stream = TRUE)
    {
        $options = new Options();
        $options->set('isRemoteEnabled', TRUE);
        $dompdf = new Dompdf($options);
        $dompdf->loadHtml($html);
        $dompdf->setPaper($paper, $orientation);
        $dompdf->render();
        $output = $dompdf->output();
        file_put_contents('' . $lokasi_file . '' . $file_pdf . '.pdf', $output, $stream = TRUE);
    }
    public function generate($html, $file_pdf, $paper, $lokasi_file, $orientation)
    {
        $options = new Options();
        $options->set('isRemoteEnabled', TRUE);
        $dompdf = new Dompdf($options);
        $dompdf->loadHtml($html);
        $dompdf->setPaper($paper, $orientation);
        $dompdf->render();
        $output = $dompdf->output();
        file_put_contents('' . $lokasi_file . '' . $file_pdf . '.pdf', $output);
    }
    public function generate_laporan2($html,  $lokasi_file, $stream = TRUE, $filename = '', $paper = '', $orientation = '')
    {
        $options = new Options();
        $options->set('isRemoteEnabled', TRUE);
        $dompdf = new Dompdf($options);
        $dompdf->loadHtml($html);
        $dompdf->setPaper($paper, $orientation);
        $dompdf->render();
        $output = $dompdf->output();
        file_put_contents('' . $lokasi_file . '' . $filename . '.pdf', $output);
    }
    public function generate_kasir($html, $file_pdf, $paper, $lokasi_file, $orientation, $stream = TRUE)
    {
        $options = new Options();
        $options->set('isRemoteEnabled', TRUE);
        $dompdf = new Dompdf($options);
        $dompdf->loadHtml($html);
        $dompdf->setPaper($paper, $orientation);
        $dompdf->render();
        $output = $dompdf->output();
        file_put_contents('' . $lokasi_file . '' . $file_pdf, $output);
    }
    public function generate_gaji($html,  $lokasi_file, $passpdf, $stream = TRUE, $filename = '', $paper = '', $orientation = '')
    {
        $options = new Options();
        $options->set('isRemoteEnabled', TRUE);
        $dompdf = new Dompdf($options);
        $dompdf->setPaper($paper, $orientation);
        $dompdf->loadHtml($html);
        $dompdf->render();
        $dompdf->getCanvas()->get_cpdf()->setEncryption($passpdf, $passpdf, ['print', 'modify', 'copy', 'add']);
        $output = $dompdf->output();
        file_put_contents('' . $lokasi_file . '' . $filename, $output);
    }
    public function generate_kontrak($html, $stream = TRUE, $filename = '', $paper = '', $orientation = '')
    {
        $options = new Options();
        $options->set('isRemoteEnabled', TRUE);
        $dompdf = new Dompdf($options);
        $dompdf->loadHtml($html);
        $dompdf->setPaper($paper, $orientation);
        $dompdf->render();
        if ($stream) {
            $dompdf->stream($filename . ".pdf", array("Attachment" => 0));
            exit();
        } else {
            return $dompdf->output();
        }
    }
}
