72 lines
2.9 KiB
PHP
72 lines
2.9 KiB
PHP
<?php
|
|
//error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
|
|
//ini_set('display_errors', 'On');
|
|
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|
|
|
if (isset($_GET['id']) && $_SESSION['id']) {
|
|
$user_id = intval($_SESSION['id']);
|
|
$get = clearInputData($_GET);
|
|
if (boolval($get['view_pdf']) || boolval($get['download_pdf']) || boolval($get['save_pdf'])) {
|
|
$doc = Docs::getInnerDoc(null, $get['id']);
|
|
if ($doc['id'] && $doc['content']) {
|
|
|
|
require_once(__DIR__ . '/vendor/autoload.php');
|
|
|
|
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
|
|
$fontDirs = $defaultConfig['fontDir'];
|
|
$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
|
|
$fontData = $defaultFontConfig['fontdata'];
|
|
|
|
$settings = [
|
|
'mode' => 'utf-8',
|
|
'format' => 'A4',
|
|
'orientation' => 'P',
|
|
'margin_left'=> 25,
|
|
'margin_right'=> 15,
|
|
'margin_top'=> 15,
|
|
'margin_bottom'=> 15,
|
|
'margin_header'=> 10,
|
|
'margin_footer'=> 10,
|
|
'fontDir' => array_merge($fontDirs, [__DIR__ . '/engine/fonts']),
|
|
'fontdata' => $fontData + [
|
|
'times' => [
|
|
'R' => 'Times-New-Roman.ttf',
|
|
'B' => 'Times-New-Roman-Bold.ttf',
|
|
]
|
|
],
|
|
'default_font' => 'times'
|
|
];
|
|
|
|
try {
|
|
$mpdf = new \Mpdf\Mpdf($settings);
|
|
$mpdf->SetTitle($doc['name']);
|
|
$stylesheet = file_get_contents(__DIR__.'/engine/style.css');
|
|
$mpdf->WriteHTML($stylesheet, \Mpdf\HTMLParserMode::HEADER_CSS);
|
|
$mpdf->WriteHTML($doc['content']);
|
|
|
|
$file_name = Docs::stringToTranslit($doc['name']) . ".pdf";
|
|
$full_path = $_SERVER['DOCUMENT_ROOT'] . "/pdf/" . $doc['agency_id'] . '-' . $doc['id'] . '-' . $file_name;
|
|
|
|
/* OUTPUT PDF */
|
|
if (boolval($get['view_pdf'])) {
|
|
$mpdf->Output($file_name, \Mpdf\Output\Destination::INLINE);
|
|
} else if (boolval($get['download_pdf'])) {
|
|
$mpdf->Output($file_name, \Mpdf\Output\Destination::DOWNLOAD);
|
|
} else if (boolval($get['save_pdf'])) {
|
|
$mpdf->Output($full_path, \Mpdf\Output\Destination::FILE);
|
|
echo json_encode(['pdf' => $full_path]);
|
|
}
|
|
|
|
// Cleanup PDF
|
|
unlink($full_path);
|
|
exit();
|
|
} catch(\Mpdf\MpdfException $e) {
|
|
echo $e->getMessage();
|
|
}
|
|
}
|
|
} else {
|
|
$doc = Docs::getInnerDoc(null, $get['id']);
|
|
echo json_encode(((isset($doc)) ? $doc : []));
|
|
}
|
|
} |