Create PDF and show Arabic using TCPDF

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
Veteran Member
Posts: 112
Joined: 2016-12-16 16:49

Create PDF and show Arabic using TCPDF

Post by xbox2007 » 2022-04-08 13:11

on this post i share my code to make PDF file using TCPDF

download TCPDF from this here

i make NEW folder name report and extract TCPDF into tcpdf folder

1- make button from Print PDF on hooks file (My table name is Employee)

Code: Select all

	function Employee_dv($selectedID, $memberInfo, &$html, &$args) {
		if(isset($_REQUEST['dvprint_x'])) return;
		ob_start(); ?>
				<?php if($selectedID){ ?>
					$j('#Employee_dv_action_buttons .btn-toolbar').append(
						'<div class="btn-group-vertical btn-group-lg" style="width: 100%;">' +
							'<button type="button" class="btn btn-warning btn-lg" onclick="Emp_Archive()">' +
								'<i class="glyphicon glyphicon-collapse-up"></i> Archive </button>' +
							'<button type="button" class="btn btn-info btn-lg" onclick="Report()">' +
								'<i class="glyphicon glyphicon-ok"></i> Report </button>' +
				<?php } ?>
			function Emp_Archive(){
				var selectedID = '<?php echo urlencode($selectedID); ?>';
				window.location = 'report/Archive.php?EmpID=' + selectedID;
			function Report(){
				var selectedID = '<?php echo urlencode($selectedID); ?>';
				window.location = 'report/Emp_pdf.php?EmpID=' + selectedID;

		$form_code = ob_get_contents();
		$html .= $form_code;
2- create Emp_pdf.php file on report folder
and add this code

Code: Select all

    $report_dir  = dirname(__FILE__);
    include("$report_dir /../lib.php");
	$Emp_id = intval($_REQUEST['EmpID']);	
	$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
	// remove default header/footer
	// set auto page breaks
	$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
	// set font
	$pdf->SetFont('aealarabiya', '', 13);

	// add a page

	$res  = sql("SELECT t1.Code, t1.EmployeeName, t1.Work_Status, t1.Start_Work ,t2.Status FROM employee t1 join Status t2 on t1.Status=t2.ID WHERE t1.ID = {$Emp_id}", $eo);
		while($row = db_fetch_assoc($res)){
			$cosas[] = $row;
	$html = '';

	foreach($cosas as $row){
		$Code = $row['Code'];
		$EmployeeName = $row['EmployeeName'];
		$Status = $row['Status'];
		$Work_Status = $row['Work_Status'];
		$Start_Work = $row['Start_Work'];
			$html .= '<><h2 align="center"><font color="#000066"><b>بسم الله الرحمن الرحيم</font></h2>'; 
			$html .= '<><h2 align="center"><font color="#FF0000"><b>اختبار إنشاء ملف بالعربية</font></h2>'; 
			$html .= '<><h2 align="center"><font color="#000066"><b>'.$Code.'</b></font><font color="#FF0000"> - '.$EmployeeName.'</font></h2>'; 
			$html .= '
			<table nobr="true" border="1" cellpadding="5" align="center">
					<td><font color="#FF0000">Status</font></td>
					<td><font color="#FF0000">Work Status</font></td>
					<td><font color="#FF0000">Start Work</font></td>
					<td><font color="#FF0000">Start Work</font></td>

	$pdf->SetFont('aealarabiya', '', 10);
	$pdf->writeHTML($html, true, 0, true, 0);

	$pdffile= $pdf->output('Reporte.pdf', 'I');
and this is result
Screenshot 2022-04-08 at 16-07-25 Emp_pdf.php.png
Screenshot 2022-04-08 at 16-07-25 Emp_pdf.php.png (24.52 KiB) Viewed 170 times

Post Reply