33namespace App \Http \Controllers ;
44
55
6+ use Dompdf \Dompdf ;
67use PhpOffice \PhpWord \IOFactory ;
8+ use PhpOffice \PhpWord \PhpWord ;
79use PhpOffice \PhpWord \Settings ;
10+ use PhpOffice \PhpWord \Shared \Html ;
811use PhpOffice \PhpWord \TemplateProcessor ;
912use Vish4395 \LaravelFileViewer \LaravelFileViewer ;
1013
@@ -15,20 +18,20 @@ public function index()
1518 {
1619 //get variables from docx file
1720 $ filepath = storage_path ('app/public/documents/test.docx ' );
18- $ templateProcessor = new TemplateProcessor ($ filepath );
21+ // $templateProcessor = new TemplateProcessor($filepath);
1922// $variables = $templateProcessor->getVariables();
2023// foreach ($variables as $variable){
2124// dd($variable);
2225// }
2326
2427 //set value to variable
25- $ templateProcessor ->setValues (array ('name ' => 'John Doe ' , 'email ' => 'John@gmail.com ' ,'phone ' => '01928472474 ' ));
28+ // $templateProcessor->setValues(array('name' => 'John Doe', 'email' => 'John@gmail.com','phone' => '01928472474'));
2629
2730 //save the updated file
28- $ updatepath = storage_path ('app/public/documents/testUpdate.docx ' );
29- $ templateProcessor ->saveAs ($ updatepath );
31+ // $updatepath = storage_path('app/public/documents/testUpdate.docx');
32+ // $templateProcessor->saveAs($updatepath);
3033
31- //convert docx to pdf
34+ //convert docx to pdf without original style
3235 $ pdfpath = storage_path ('app/public/documents/test.pdf ' );
3336
3437 $ domPdfPath = base_path ('vendor/dompdf/dompdf ' );
@@ -38,6 +41,32 @@ public function index()
3841 $ PDFWriter = IOFactory::createWriter ($ Content ,'PDF ' );
3942 $ PDFWriter ->save ($ pdfpath );
4043
44+ 45+ 46+ // Save the document as HTML
47+ // $filepath = storage_path('app/public/documents/test.docx');
48+ // Settings::setOutputEscapingEnabled(true);
49+ // $phpWord = IOFactory::load($filepath);
50+ // $xmlWriter = IOFactory::createWriter($phpWord, 'HTML');
51+ // $htmlFilePath = storage_path('app/public/documents/' . 'test' . '.html');
52+ // $xmlWriter->save($htmlFilePath);
53+ 54+ // Convert the HTML to PDF using DOMPDF
55+ // $dompdf = new Dompdf();
56+ // $html = file_get_contents($htmlFilePath);
57+ // $dompdf->loadHtml($html);
58+ // $dompdf->setPaper('A4', 'portrait');
59+ // $dompdf->render();
60+ //
61+ // $pdfpath = storage_path('app/public/documents/test.pdf');
62+ // $pdf_output = $dompdf->output();
63+ // file_put_contents($pdfpath, $pdf_output);
64+ 65+ // Delete the temporary files
66+ // unlink($htmlFilePath);
67+ 68+ 69+ 4170 return redirect ('/ ' );
4271 }
4372
0 commit comments