Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting is lost when converting to PDF #1837

Open
atiladelcanton opened this issue Mar 11, 2020 · 0 comments
Open

Formatting is lost when converting to PDF #1837

atiladelcanton opened this issue Mar 11, 2020 · 0 comments

Comments

@atiladelcanton
Copy link

atiladelcanton commented Mar 11, 2020

Good Morning!

I have a docx, where I do replace the template and need to export to PDF, but when I do export it loses all formatting.

Do I need something more?

    $templateCCB = new TemplateProcessor(public_path() . '/template_ccb.docx');
            $templateCCB->setValues($sanitizedData);
            $templateCCB->saveAs(public_path() . '/tmp.docx');

            \PhpOffice\PhpWord\Settings::setPdfRendererPath(base_path() . '/vendor/dompdf/dompdf');
            \PhpOffice\PhpWord\Settings::setPdfRendererName('DomPDF');

            $phpWord = \PhpOffice\PhpWord\IOFactory::load(public_path() . '/tmp.docx');

            $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'PDF');
            $xmlWriter->save(public_path() . '/result.pdf');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant