API untuk convert data ke PDF menggunakan password

 Berikut function API untuk membuat file PDF. File PDF akan ada paaword ketika di buka.

function Render(){

$this->load->library('M_pdf');

$json = file_get_contents('php://input');

$data = json_decode($json, true);


if (!$data) {

show_error('Invalid input', 400);

return;

}


$html_content = $data['html'] ?? '<h1>No content provided</h1>';

$filename = $data['filename'] ?? 'document.pdf';

$password = $data['password'] ?? null;


try {

$mpdf = new \Mpdf\Mpdf();


// Kalau ada password, aktifkan proteksi

if ($password) {

$mpdf->SetProtection([], $password, '12345');

}


$mpdf->WriteHTML($html_content);


header('Content-Type: application/pdf');

header('Content-Disposition: attachment; filename="' . $filename . '"');

header('Access-Control-Allow-Origin: *');


$mpdf->Output($filename, \Mpdf\Output\Destination::INLINE);

} catch (Exception $e) {

show_error($e->getMessage(), 500);

}

}

NextGen Digital... Welcome to WhatsApp chat
Howdy! How can we help you today?
Type here...