eOSP2/app/Http/Controllers/documentOverlayController.php

113 lines
3.5 KiB
PHP
Raw Normal View History

2020-03-25 00:20:45 +01:00
<?php
namespace App\Http\Controllers;
use Codedge\Fpdf\Fpdf\Fpdf;
use Illuminate\Http\Request;
use setasign\Fpdi\Fpdi;
class documentOverlayController extends Controller
{
//
2020-06-13 00:02:05 +02:00
public function peselBirthDay($pesel){
$pesel = (String) $pesel;
$output = $pesel[2];
$output = (int)$output;
if( $output == 0 || $output == 1){
$year = '19'."".(String)$pesel[0]."".(String)$pesel[1];
}elseif( $output == 2 || $output == 3){
$year = '20'."".(String)$pesel[0]."".(String)$pesel[1];
}elseif( $output == 4 || $output == 5){
$year = '21'."".(String)$pesel[0]."".(String)$pesel[1];
}elseif( $output == 6 || $output == 7){
$year = '22'."".(String)$pesel[0]."".(String)$pesel[1];
}elseif( $output == 8 || $output == 9){
$year = '18'."".(String)$pesel[0]."".(String)$pesel[1];
}
if($output % 2 == 0 ){
$month = '0'."".(String)$pesel[3];
}else{
$month = '1'."".(String)$pesel[3];
}
$day = (String)$pesel[4]."".(String)$pesel[5];
return $day.".".$month.".".$year;
}
public function testPdf($userData, $decoration, $fireStation){
2020-03-25 00:20:45 +01:00
// initiate FPDI
$pdf = new Fpdi();
// set the source file
$pageCount = $pdf->setSourceFile("../app/Http/Controllers/documentTemplates/a.pdf");
// import page 1
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
// import a page
$templateId = $pdf->importPage($pageNo);
// get the size of the imported page
$size = $pdf->getTemplateSize($templateId);
// create a page (landscape or portrait depending on the imported page size)
if ($size[0] > $size[1]) {
$pdf->AddPage('L', array($size[0], $size[1]));
} else {
$pdf->AddPage('P', array($size[0], $size[1]));
}
$pdf->useTemplate($templateId);
if($pageNo == 1){
$str = iconv('UTF-8', 'cp1250', 'zazółcić gęślą jaźń');
2020-06-13 00:02:05 +02:00
// $xyz = iconv('UTF-8', 'cp1250', $fireFighterID);
$dec = iconv('UTF-8', 'cp1250', $decoration);
2020-03-25 00:20:45 +01:00
// now write some text above the imported page
$pdf->SetFont('times');
2020-06-13 00:02:05 +02:00
$pdf->SetTextColor(128, 128, 128);
#Pieczęć
2020-03-25 00:20:45 +01:00
$pdf->SetXY(30, 30);
2020-06-13 00:02:05 +02:00
// $pdf->Write(0, $decoration);
#Nazwa odznaczenia
$pdf->SetXY(120, 50);
//$pdf->Write(0, $decoration);
$pdf->Cell(20,10, $decoration, 1, 0, 'C');
#Imie
$pdf->SetXY(35, 74);
//$pdf->Write(0, $decoration);
$pdf->Cell(20,10, $userData->name, 1, 0, 'C');
#Nazwisko
$pdf->SetXY(95, 74);
//$pdf->Write(0, $decoration);
$pdf->Cell(20,10, $userData->surname, 1, 0, 'C');
#Data Urodzenia
$pdf->SetXY(35, 93);
//$pdf->Write(0, $decoration);
$pdf->Cell(20,10, $this->peselBirthDay($userData->PESEL), 1, 0, 'C');
#Funkcja
$pdf->SetXY(124, 113);
$pdf->Cell(20,10, $userData->unitFunction, 1, 0, 'C');
#Funkcja
$pdf->SetXY(35, 113);
$pdf->Cell(20,10, $fireStation->postOffice, 1, 0, 'C');
2020-03-25 00:20:45 +01:00
}
}
$pdf->Output();
}
}