如何使用PHP将dom pdf生成的pdf文件添加到ZipArchive

I have used dom pdf to create a .pdf file from html text content. At the same time I have to create a zip archive and add that pdf file to zip.

That zip contains more two folders as well. I am stuck while adding DOMPDF generated file to the zip archive. Can anyone provide me a solution for this?

Use this code to make pdf file from html content.

$html = "put your html code here";
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "portrait");
$dompdf->render();
$output = $dompdf->output();
file_put_contents('Otherfile.pdf', $output);

After using render() function use output() function to store pdf file in variable. And put that content inside new file using file_put_contents(). Then use that file to put inside .zip using following code.

$files = 'Otherfile.pdf';
$zipname = 'zipname.zip';
$zip = new ZipArchive;      
$zip->open($zipname, ZipArchive::OVERWRITE);
$zip->addFile($files);

$zip->close();
header('Content-Type: application/zip');
header("Content-Disposition: attachment; filename='".$zipname."'");
header("Pragma: no-cache"); 
header("Expires: 0");
header('Cache-Control: must-revalidate');
header('Content-Length: ' . filesize($zipname));