Skip to content

Instantly share code, notes, and snippets.

@abcprintf
Created September 24, 2018 15:09
Show Gist options
  • Save abcprintf/f3600c180f586033eb48e7470a74b32a to your computer and use it in GitHub Desktop.
Save abcprintf/f3600c180f586033eb48e7470a74b32a to your computer and use it in GitHub Desktop.
how to convert .docx to .pdf [PHPword]
$rendererLibraryPath = PHPWORD_BASE_DIR . '/vendor/dompdf/dompdf';
\PhpOffice\PhpWord\Settings::setPdfRendererPath($rendererLibraryPath);
\PhpOffice\PhpWord\Settings::setPdfRendererName('DomPDF');
$phpWord = new \PhpOffice\PhpWord\PhpWord();
//Load temp file
$phpWord = \PhpOffice\PhpWord\IOFactory::load('.docx');
//Save it
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'PDF');
$xmlWriter->save('xx.pdf');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'HTML');
$xmlWriter->save('xx.html');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment