|
|
|
mpdf นำเข้าไฟล์ pdf แล้ว html ไม่อยู่หน้า 1 ไปอยู่ในหน้า 2 แทน |
|
|
|
|
|
|
|
Code (PHP)
<?php
session_start();
if (!isset($_SESSION['username'])) {
header('location: index.php');
}
if(!isset($_POST['id_p']) ){
header('location: index.php');
}
require('connect.php');
$id = mysqli_real_escape_string($con, $_POST['id_p']);
//รับค่า school
$query_school = "SELECT `name` FROM `system` ";
$result_school = mysqli_query($con,$query_school);
if (false === $result_school) {
die(mysqli_error($con));
}
while ($row_school = mysqli_fetch_assoc($result_school)) {
$school_data = $row_school['name'];
break;
}
require_once __DIR__ . '/vendor/autoload.php';
// โหลด Liblary mPDF
$mpdf = new \Mpdf\Mpdf( [
'format' => 'A4',
'mode' => 'utf-8',
'default_font' => 'sarabun',
'default_font_size' => '16',
'tempDir' => '/tmp',
] );
//รับค่า picture_std
$query_picture_std = "SELECT `picture_std` FROM `request` WHERE `id` =".$id;
$result_picture_std = mysqli_query($con,$query_picture_std);
if (false === $result_picture_std) {
die(mysqli_error($con));
}
while ($row_picture_std = mysqli_fetch_assoc($result_picture_std)) {
$picture_std = $row_picture_std['picture_std'];
break;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>ระบบร้องขอเอกสารทางการศึกษา | <?=$school_data?></title>
<meta content='width=device-width, initial-scale=1.0, shrink-to-fit=no' name='viewport' />
<link rel="icon" href="img/fav.ico" type="image/x-icon"/>
</head>
<body>
<img src="upload/picture-std/<?=$picture_std?>" >
</body>
</html>
<?php
//รับค่า name
$query_name = "SELECT `name` FROM `request` WHERE `id` =".$id;
$result_name = mysqli_query($con,$query_name);
if (false === $result_name) {
die(mysqli_error($con));
}
while ($row_name = mysqli_fetch_assoc($result_name)) {
$name_data = $row_name['name'];
break;
}
//รับค่า iddoc
$query_iddoc = "SELECT `id_doc` FROM `request` WHERE `id` =".$id;
$result_iddoc = mysqli_query($con,$query_iddoc);
if (false === $result_iddoc) {
die(mysqli_error($con));
}
while ($row_iddoc = mysqli_fetch_assoc($result_iddoc)) {
$iddoc_data = $row_iddoc['id_doc'];
break;
}
//รับค่า HTML
$html = ob_get_contents();
$html = ob_get_clean();
//template
$pagecount = $mpdf->SetSourceFile('upload/sgs/sgs-5-09936_1629649264.pdf');
for ($i=1; $i<=($pagecount); $i++) {
$mpdf->AddPage();
$import_page = $mpdf->ImportPage($i);
$mpdf->UseTemplate($import_page);
}
/*
for ($i = 2; $i <= $pagecount; $i++)
{
$mpdf->AddPage(); // Add page to output document
$tplId = $mpdf->ImportPage($i); // Import page as a template
$mpdf->UseTemplate($tplId); // insert the template in the added page
}
*/
$mpdf->WriteHTML($html);
$mpdf->Output(''.$name_data." (".$iddoc_data.")".'.pdf', 'I');
ob_end_flush();
?>
Tag : PHP
|
ประวัติการแก้ไข 2021-08-23 08:57:50 2021-08-23 10:58:53
|
|
|
|
|
Date :
2021-08-23 08:56:55 |
By :
jgogo01 |
View :
1479 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WriteHTML() ก่อน AddPage()
|
|
|
|
|
Date :
2021-08-23 12:10:26 |
By :
TheGreatGod_of_Death |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|