connect_error) { die(json_encode(["error" => "Connection failed: " . $conn->connect_error])); } $stmt = $conn->prepare("SELECT * from company"); $stmt->execute(); $result = $stmt->get_result(); $logoname = $result->fetch_all(MYSQLI_ASSOC); $stmt = $conn->prepare("DELETE from reportsections"); $stmt->execute(); $stmt = $conn->prepare("INSERT INTO reportsections ( cover_title, cover_subtitle, instructionsdetails_title, instructiondetails_text, overviewstatistic_title, overviewstatistic_text, supplieristatistic_title, supplieristatistic_text, analysisstatistic_title, analysisstatistic_text, analytscompounds_title, analytscompounds_text, finalevaluation_title, finalevaluation_text ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); if ($stmt === false) { die(json_encode(["error" => "Prepare statement failed: " . $conn->error])); } $stmt->bind_param( 'ssssssssssssss', $title[0], $content[0], $title[1], $content[1], $title[2], $content[2], $title[3], $content[3], $title[4], $content[4], $title[5], $content[5], $title[6], $content[6] ); if (!$stmt->execute()) { die(json_encode(["error" => "Execute statement failed: " . $stmt->error])); } $stmt->close(); $conn->close(); $chartdata0 = file_get_contents('../../../resources/charts/chart0.ch'); $chartdata1 = file_get_contents('../../../resources/charts/chart1.ch'); $chartdata2 = file_get_contents('../../../resources/charts/chart2.ch'); $chartdata3 = file_get_contents('../../../resources/charts/chart3.ch'); $chartdata4 = file_get_contents('../../../resources/charts/chart4.ch'); $chartdata5 = file_get_contents('../../../resources/charts/chart5.ch'); $tmplogo = file_get_contents('../uploadlogo/' . $logoname[0]['logocompany']); $base64logo = base64_encode($tmplogo); $logodata = 'data:image/jpeg;base64,' . $base64logo; $page = ' Financial Report
Date: ' . $currentDate . '
' . $title[0] . '
' . $content[0] . '
Created by: ' . $nameuser . '
Date ' . $currentDate . '

' . $title[1] . '


' . $content[1] . '

FILTERS APPLIED

From Date ' . $filterStart . ' to Date ' . $filterEnd . '

Other Filters

' . $title[2] . '


' . $content[2] . '

' . $title[3] . '


' . $content[3] . '

' . $title[4] . '


' . $content[4] . '

' . $title[5] . '


' . $content[5] . '

' . $title[6] . '


' . $content[6] . '

'; $options = new Options(); $options->set('isHtml5ParserEnabled', true); $options->set('isRemoteEnabled', true); $dompdf = new Dompdf($options); $dompdf->loadHtml($page); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); $filePath = "../../download/"; $filename = "Report" . date('d-m-Y-H-i') . ".pdf"; if (!is_dir('../../download/')) { mkdir('../../download/', 0777, true); } file_put_contents($filePath . $filename, $dompdf->output()); if (file_exists($filePath . $filename)) { $response['status'] = 'success'; $response['message'] = 'http://127.0.0.1/reportifynew/public/download/'; $response['file'] = $filename; } else { $response['status'] = 'error'; $response['message'] = 'PDF download fail'; } echo json_encode($response);