PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.27k stars 2.7k forks source link

How to convert docx to pdf with mathtype #2062

Open Windd01 opened 3 years ago

Windd01 commented 3 years ago

Im trying to convert .docx file to .pdf with code below :

$domPdfPath = base_path('vendor/dompdf/dompdf'); Settings::setPdfRendererPath($domPdfPath); Settings::setPdfRendererName('DomPDF'); $Content = IOFactory::load('test.docx'); $Content->setDefaultFontName('Roboto'); $PDFWriter = IOFactory::createWriter($Content, 'PDF'); $PDFWriter->save('test.pdf');

But mathtype and vietnamese in .docx cannot converted. Mathtype throwed something like : <Object: word/embeddings/oleObject1.bin>

JBavaliya commented 3 years ago

@Windd01

Try this working example. .docx to .pdf conversion

        $docxPath = 'abc.docx';
        $pdfPath = 'abc.pdf';

        $domPdfPath = realpath('/vendor/dompdf/dompdf');
        \PhpOffice\PhpWord\Settings::setPdfRendererPath($domPdfPath);
        \PhpOffice\PhpWord\Settings::setPdfRendererName('DomPDF');

        $phpWord = new \PhpOffice\PhpWord\PhpWord();
        $phpWord = \PhpOffice\PhpWord\IOFactory::load($docxPath); 

        $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'PDF');
        $xmlWriter->save($pdfPath); 
thoanv commented 3 years ago

@JBavaliya Thank you I did the same as you But I get an error it's a font error Hope you help