Skip to content

Instantly share code, notes, and snippets.

@catwhocode
Created July 27, 2023 13:34
Show Gist options
  • Save catwhocode/d79efec997755d5a004268d91cdf2afe to your computer and use it in GitHub Desktop.
Save catwhocode/d79efec997755d5a004268d91cdf2afe to your computer and use it in GitHub Desktop.
Convert DOCX file to PDF
<?php
// source:
// https://github.com/yuya-takeyama/php-docx2pdf/blob/master/docx2pdf.php
require 'vendor/autoload.php';
\PhpOffice\PhpWord\Settings::setPdfRendererPath('vendor/tecnickcom/tcpdf');
\PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF');
$temp = \PhpOffice\PhpWord\IOFactory::load('dokumen.docx', 'Word2007');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($temp , 'PDF');
$xmlWriter->save('hasil.pdf', true);
echo "Done converting to PDF \n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment