Convert Word to PDF

Hello,I put the code below in "row action event"The code works but the layout of the PDF file disappears.Thank you very much!

// Row Custom Action event
     public function rowCustomAction($action, $row)
       {
  
        	$leerling = ExecuteScalar("SELECT concat(famnaam_ll,' ',voornaam_ll) FROM stageovereenkomsten WHERE ID_stage = '".$row'idstage']."'");
             
		 $file = 'evaluatie '.$leerling.' '.$row['datum'].' door '.$currentuser.'.docx';
              header("Content-Description: File Transfer");
              header('Content-Disposition: attachment; filename="' . $file . '"');
              header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
              header('Content-Transfer-Encoding: binary');
              header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
              header('Expires: 0');
             
          $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('./uploads/templates/evaluatieblad.docx');
    
	$schooljaar = ExecuteScalar("SELECT schooljaar FROM afdruk WHERE ID_stage = '".$row['idstage']."'");
   	 $bedrijf = ExecuteScalar("SELECT bedrijf_naam FROM afdruk WHERE ID_stage = '".$row['idstage']."'");
    	$logo = ExecuteScalar("SELECT bedrijfslogo FROM afdruk WHERE ID_stage = '".$row['idstage']."'");

  
      $templateProcessor->setValue('schooljaar', $schooljaar);
      setlocale(LC_ALL, array('nl_NL.UTF-8','nl_NL@euro','nl_NL','dutch'));
       $templateProcessor->setValue('datum', strftime('%A %d %b %Y', strtotime($row['datum'])));
      $templateProcessor->setValue('bedrijf', $bedrijf);
      $templateProcessor->setValue('naamll', $leerling);
      $templateProcessor->setValue('klas', $row['klas']);
 
    //$templateProcessor->saveAs('php://output');
$templateProcessor->saveAs('/temp/test.docx');
   
      \PhpOffice\PhpWord\Settings::setPdfRendererPath('./vendor/hvkstore/dompdf');
        \PhpOffice\PhpWord\Settings::setPdfRendererName('DOMPDF');
      
         
        $phpWord = \PhpOffice\PhpWord\IOFactory::load('c:/temp/test.docx');
       $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'PDF');
       $xmlWriter->save('php://output');
     $xmlWriter->save('c:/temp/test.pdf');
}

You may refer to the code in the generated /src/ExportPdf.php file. As you can see, you may include the styles that already defined in related .css file.Make sure you have already enabled dompdf from Tools → Extensions → PDF Export, before re-generating ALL the script files.

Hi,
I would like also know how is the solutions for this code.
I am getting the following error for PDF part:C:\xampp\htdocs\2021\phpword\vendor\phpoffice\phpword\src\PhpWord\Writer\PDF.php(50): PDF rendering library or library path has not been defined.mpol_ch

mpol_ch wrote:

how is the solutions for this code.

Always post your code for more discussion.

Hi,
I am using the below code and I am getting this error: Class ‘PHPMaker2021\phpword\Settings’ not foundSettings::setPdfRendererName(Settings::PDF_RENDERER_DOMPDF);
Settings::setPdfRendererPath(‘./vendor/hvkstore/dompdf’);$phpWord = IOFactory::load(‘./mpol/Rechnung.docx’, ‘Word2007’);
$phpWord->save(‘./mpol/document.pdf’, ‘PDF’);mpol_ch

You need to use namespace when you use third party classes, read Using namespaces: Basics.