Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/contracts/
Upload File :
Current File : /var/www/cesa.co.za/contracts/sample.php

<?php

// echo 'Please contact CESA if you are still using this feature.';
// exit;

include("../php/inc_db.php");

require_once('fpdf184/fpdf.php');
require_once('FPDI-2.3.6/src/autoload.php');

$pdf = new setasign\Fpdi\Fpdi('P','mm','A4'); 

$sql="SELECT PDFTemplate FROM ContractTypes WHERE ContractTypeID=".intval($_GET["id"]);
$rec=mysqli_query($conni,$sql);
if ($row=mysqli_fetch_assoc($rec)) {
	if (!file_exists(CONTRACTS_DIR.'wm_sec_'.$row["PDFTemplate"])) {
		$pagecount = $pdf->setSourceFile(CONTRACTS_DIR.$row["PDFTemplate"]); 
		for ($i=1; $i<=$pagecount; $i++) {
			$tplidx = $pdf->importPage($i, '/MediaBox'); 
			$pdf->AddPage(); 
			$pdf->SetMargins(255,255,255);
			$pdf->useTemplate($tplidx, 0, 0, 215); 
			$pdf->SetTextColor(153,153,153);
			$pdf->SetFont('Arial','B',124);
			$pdf->Text(30,120,'SAMPLE');
		}
		$pdf->Output(CONTRACTS_DIR.'watermark_'.$row["PDFTemplate"], 'F'); 
		
		$sOutputFile='"'.CONTRACTS_DIR.'wm_sec_'.$row["PDFTemplate"].'"';
		$sFilelist=' "'.CONTRACTS_DIR.'watermark_'.$row["PDFTemplate"].'"';
		
		exec('gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOwnerPassword=C354 -dKeyLength=128 -dEncryptionR=3 -dPermissions=-1852 -sOutputFile='.$sOutputFile.$sFilelist);
		
		unlink(CONTRACTS_DIR.'watermark_'.$row["PDFTemplate"]);
		
	}
	header("Content-type: application/pdf");
	readfile(CONTRACTS_DIR.'wm_sec_'.$row["PDFTemplate"]);
	
}
mysqli_free_result($rec);

//TODO: Add code to close mysql connections
mysqli_close($conni);