public function return_pdf()
 {
     $Condition = $this->uri->segment(4);
     /*
     $Condition  1 == Batch Id wise printing.
     2 == Final Group wise prining.
     3 == Final Formno wise Printing.
     4 == Proof reading Group wise Printing.
     5 == Proof reading Formno wise Printing.
     */
     // DebugBreak();
     $this->load->library('session');
     $Logged_In_Array = $this->session->all_userdata();
     $user = $Logged_In_Array['logged_in'];
     $this->load->model('Registration_model');
     if ($Condition == "1") {
         $Batch_Id = $this->uri->segment(3);
         $fetch_data = array('Inst_cd' => $user['Inst_Id'], 'Batch_Id' => $Batch_Id);
         $result = array('data' => $this->Registration_model->return_pdf($fetch_data), 'inst_Name' => $user['inst_Name']);
     } else {
         if ($Condition == "2") {
             $grp_cd = $this->uri->segment(3);
             $fetch_data = array('Inst_cd' => $user['Inst_Id'], 'grp_cd' => $grp_cd);
             $result = array('data' => $this->Registration_model->Print_Form_Groupwise($fetch_data));
         } else {
             if ($Condition == "3") {
                 $start_formno = $this->uri->segment(3);
                 $end_formno = $this->uri->segment(5);
                 $fetch_data = array('Inst_cd' => $user['Inst_Id'], 'start_formno' => $start_formno, 'end_formno' => $end_formno);
                 $result = array('data' => $this->Registration_model->Print_Form_Formnowise($fetch_data));
             } else {
                 if ($Condition == "4") {
                     $grp_cd = $this->uri->segment(3);
                     $fetch_data = array('Inst_cd' => $user['Inst_Id'], 'grp_cd' => $grp_cd);
                     $result = array('data' => $this->Registration_model->Print_Form_Groupwise($fetch_data), 'inst_Name' => $user['inst_Name']);
                 } else {
                     if ($Condition == "5") {
                         $start_formno = $this->uri->segment(3);
                         $end_formno = $this->uri->segment(5);
                         $fetch_data = array('Inst_cd' => $user['Inst_Id'], 'start_formno' => $start_formno, 'end_formno' => $end_formno);
                         $result = array('data' => $this->Registration_model->Print_Form_Formnowise($fetch_data), 'inst_Name' => $user['inst_Name']);
                     }
                 }
             }
         }
     }
     // DebugBreak();
     if (empty($result['data'])) {
         $this->session->set_flashdata('error', $Condition);
         redirect('Registration/FormPrinting');
         return;
     }
     $temp = $user['Inst_Id'] . '09-2016-18';
     $image = $this->set_barcode($temp);
     // $pdf->Image(base_url().'assets/pdfs/'.'/'.$image,6.3,0.5, 1.8, 0.20, "PNG");
     //$studeninfo['data']['info'][0]['barcode'] = $image;
     $this->load->library('PDF_Rotate');
     $pdf = new PDF_Rotate('P', 'in', "A4");
     $pdf->Rotate(0, -1, -1);
     //   $pdf->SetFont('Arial','B',50);
     //             $pdf->SetTextColor(255,192,203);
     //             $pdf->Rotate(35,190,'W a t e r m a r k   d e m o',45);
     $pdf->SetMargins(0.5, 0.5, 0.5);
     $lmargin = 0.5;
     $rmargin = 7.5;
     $topMargin = 0.5;
     $countofrecords = 14;
     $title = 1.0;
     $cnt = 0;
     $ln[0] = 1.5;
     $SR = 1;
     while ($cnt < 15) {
         $cnt++;
         $ln[$cnt] = $ln[$cnt - 1] + 0.6;
         //0.5;
     }
     $i = 4;
     $result = $result['data'];
     // DebugBreak();
     foreach ($result as $key => $data) {
         //DebugBreak();
         //DebugBreak();
         $i++;
         $countofrecords = $countofrecords + 1;
         if ($countofrecords == 15) {
             $countofrecords = 0;
             $pdf->AddPage();
             //     $pdf->SetFont('Arial','B',50);
             //                 $pdf->SetTextColor(255,192,203);
             //                 $pdf->Rotate(35,190,'W a t e r m a r k   d e m o',45);
             if ($Condition == 4 or $Condition == 5) {
                 $pdf->Image(base_url() . 'assets/img/PROOF_READ.jpg', 1, 3.5, 6, 4, "JPG");
             }
             $pdf->SetFont('Arial', 'U', 14);
             $pdf->SetXY(0.4, 0.2);
             $pdf->Cell(0, 0.2, "BOARD OF INTERMEDIATE AND SECONDARY EDUCATION, GUJRANWALA", 0.25, "C");
             $pdf->SetFont('Arial', '', 10);
             $pdf->SetXY(1.7, 0.4);
             $pdf->Cell(0, 0.25, "MATRIC PART-I ENROLMENT RETURN SESSION (2016-2018)", 0.25, "C");
             $pdf->SetFont('Arial', '', 10);
             $pdf->SetXY(2.6, 0.4);
             $pdf->Image(base_url() . 'assets/pdfs/' . '/' . $image, 6.3, 0.5, 1.8, 0.2, "PNG");
             $pdf->SetFont('Arial', '', 10);
             $pdf->SetXY(1.7, 0.6);
             $pdf->Cell(0, 0.25, $user['Inst_Id'] . "-" . $user['inst_Name'], 0.25, "C");
             $pdf->SetFont('Arial', '', 10);
             $pdf->SetXY(6.9, 0.8);
             $pdf->Cell(0, 0.25, 'Gender: ' . ($data['sex'] ? "MALE" : "FEMALE"), 0.25, "C");
             $grp_name = $data["RegGrp"];
             switch ($grp_name) {
                 case '1':
                     $grp_name = 'SCIENCE WITH BIOLOGY';
                     break;
                 case '7':
                     $grp_name = 'SCIENCE  WITH COMPUTER SCIENCE';
                     break;
                 case '8':
                     $grp_name = 'SCIENCE  WITH ELECTRICAL WIRING';
                     break;
                 case '2':
                     $grp_name = 'Humanities';
                     break;
                 case '5':
                     $grp_name = 'Deaf and Dumb';
                     break;
                 default:
                     $grp_name = "No Group Selected.";
             }
             $pdf->SetFont('Arial', '', 10);
             $pdf->SetXY(2.5, 0.8);
             $pdf->Cell(0, 0.25, 'Group: ' . $grp_name, 0.25, "C");
             $pdf->rect($lmargin, 1, $rmargin, 10.5);
             //the main rectangle box
             $cnt = -1;
             while ($cnt < 15) {
                 $cnt++;
                 $pdf->Line($lmargin, $ln[$cnt], $rmargin + 0.5, $ln[$cnt]);
             }
             $col1 = $lmargin + 0.3;
             $col2 = $col1 + 0.9;
             $col3 = $col2 + 1.8;
             $col4 = $col3 + 1.1;
             $col5 = $col4 + 1.0;
             $col6 = $col5 + 1.8;
             $pdf->Line($col1, $title, $col1, $ln[15]);
             $pdf->Line($col2, $title, $col2, $ln[15]);
             $pdf->Line($col3, $title, $col3, $ln[15]);
             $pdf->Line($col4, $title, $col4, $ln[15]);
             $pdf->Line($col5, $title, $col5, $ln[15]);
             $pdf->Line($col6, $title, $col6, $ln[15]);
             $pdf->SetFont('Arial', 'B', 9);
             $pdf->Text($lmargin + 0.03, $title + 0.3, "Sr#");
             //$pdf->Text(3,3,"TEXT TO DISPLAY");
             $pdf->Text($col1 + 0.2, $title + 0.3, "FormNo.");
             $pdf->Text($col2 + 0.1, $title + 0.2, "Name / Father`s Name");
             $pdf->Text($col2 + 0.1, $title + 0.4, "Mobile No");
             $pdf->Text($col3 + 0.1, $title + 0.2, "Bay Form No");
             $pdf->Text($col3 + 0.1, $title + 0.4, "Father CNIC");
             $pdf->Text($col4 + 0.1, $title + 0.2, "Date Of Birth");
             $pdf->Text($col4 + 0.1, $title + 0.4, "Relegion");
             $pdf->Text($col5 + 0.1, $title + 0.3, "Subjects");
             $pdf->Text($col6 + 0.1, $title + 0.3, "Picture");
         }
         $dob = date("d-m-Y", strtotime($data["Dob"]));
         $adm = date("d-m-Y", strtotime($data["edate"]));
         //============================ Values ==========================================
         $pdf->SetFont('Arial', '', 10);
         $pdf->Text($lmargin + 0.1, $ln[$countofrecords] + 0.3, $SR);
         // Sr No
         $pdf->Text($col1 + 0.05, $ln[$countofrecords] + 0.3, $data["formNo"]);
         // Form No
         $pdf->SetFont('Arial', 'B', 8);
         $pdf->Text($col2 + 0.1, $ln[$countofrecords] + 0.2, strtoupper($data["name"]));
         $pdf->SetFont('Arial', '', 8);
         $pdf->Text($col2 + 0.1, $ln[$countofrecords] + 0.4, strtoupper($data["Fname"]));
         $pdf->SetFont('Arial', '', 7.5);
         $pdf->Text($col2 + 0.1, $ln[$countofrecords] + 0.55, strtolower($data["CellNo"]));
         $pdf->SetFont('Arial', '', 8);
         $pdf->Text($col3 + 0.1, $ln[$countofrecords] + 0.2, strtoupper($data["BForm"]));
         $pdf->Text($col3 + 0.1, $ln[$countofrecords] + 0.4, strtoupper($data["FNIC"]));
         $pdf->Text($col4 + 0.1, $ln[$countofrecords] + 0.2, strtoupper($data["Dob"]));
         $pdf->Text($col4 + 0.1, $ln[$countofrecords] + 0.4, strtoupper($data["rel"] == 1 ? "Muslim" : "Non-Muslim"));
         $pdf->SetFont('Arial', 'B', 7);
         //            $pdf->Text($col5+.05,$ln[$countofrecords]+0.2,GroupName($data["Grp_Cd"]));
         $pdf->Text($col5 + 0.05, $ln[$countofrecords] + 0.2, $data["sub1_abr"] . ',' . $data["sub2_abr"] . ',' . $data["sub3_abr"] . ',' . $data["sub4_abr"]);
         $pdf->SetFont('Arial', '', 7);
         $pdf->Text($col5 + 0.05, $ln[$countofrecords] + 0.4, $data["sub5_abr"] . ',' . $data["sub6_abr"] . ',' . $data["sub7_abr"] . ',' . $data["sub8_abr"]);
         $pdf->Image(base_url() . 'assets/uploads/' . $data["Sch_cd"] . '/' . $data["PicPath"], $col6 + 0.05, $ln[$countofrecords] + 0.05, 0.5, 0.5, "JPG");
         ++$SR;
         //Certified that I have checked all the relevant record of the students and the particulars as mentioned above are correct.
         $pdf->SetFont('Arial', '', 8);
         $pdf->Text($lmargin + 0.5, 10.8, "Certified that I have checked all the relevant record of the students and the particulars as mentioned above are correct.");
         //$pdf->Text($lmargin+.5,11,"Signature _____________________");
         $pdf->SetFont('Arial', '', 10);
         $pdf->Text($rmargin - 2.5, 11.2, "_____________________________________");
         $pdf->Text($rmargin - 2.5, 11.4, "Signature of Head of Institution with Stamp");
         $pdf->Text($lmargin + 0.5, 11.4, 'Print Date: ' . date('d-m-Y H:i:s'));
     }
     $pdf->Output();
 }