Untitled
unknown
plain_text
a year ago
1.0 kB
5
Indexable
// Convert DOCX to HTML $phpWord = IOFactory::load($filePath); $htmlWriter = IOFactory::createWriter($phpWord, 'HTML'); $htmlFilePath = FCPATH . 'downloads/' . pathinfo($newdocname, PATHINFO_FILENAME) . '.html'; $htmlWriter->save($htmlFilePath); // Convert HTML to PDF $pdfFilePath = FCPATH . 'downloads/' . pathinfo($newdocname, PATHINFO_FILENAME) . '.pdf'; $options = new Options(); $options->set('isRemoteEnabled', true); $dompdf = new Dompdf($options); $dompdf->loadHtmlFile($htmlFilePath); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); file_put_contents($pdfFilePath, $dompdf->output()); // Clean up temporary HTML file unlink($htmlFilePath); // Return URLs to both DOCX and PDF files return [ 'docx' => base_url('downloads/' . $newdocname), 'pdf' => base_url('downloads/' . pathinfo($newdocname, PATHINFO_FILENAME) . '.pdf') ];
Editor is loading...
Leave a Comment