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

Corrupted file after SaveAs from templateProcessor #2591

Open
lordkyle0 opened this issue Mar 26, 2024 · 0 comments
Open

Corrupted file after SaveAs from templateProcessor #2591

lordkyle0 opened this issue Mar 26, 2024 · 0 comments

Comments

@lordkyle0
Copy link

Describe the Bug

Get corrupted file after using TemplateProcessor.

Steps to Reproduce

I used TemplateProcessor to get my dotx file. and After getting the doc, I can't use the file generated in MS Word. When I try https://products.groupdocs.app/viewer/app, my file was opened and I've download it to pdf. Can PHPWORD make correct file for MS Word ???

try {
                Settings::setOutputEscapingEnabled(true);
                Settings::setCompatibility(false);
                // Settings::setZipClass(Settings::PCLZIP);
                $template = new TemplateProcessor(public_path('assets/templates/regidoc1.dotx'));
                $template->setMacroOpeningChars('{#');
                $template->setMacroClosingChars('#}');
                $nom1 = "FRANCIS";
                $nom2 = "ISASI";
                $nom3 = "LORD";
                $tous = 'Tous à Kinshasa';
                $to = 'DG REGIDESO';
                $date = 'KIN 26/03.2024';
                $ref = "Numéro de référence";
                $objet = "Objet de la demande";
                $body = "Ceci est le corps du document. Il peut contenir du texte enrichi, des images et des tableaux.";
                $fonction = "Votre fonction";
                $signataire = "Votre nom et votre signature";

                $template->setValue('{Nom1}', str_replace('FRANCIS', '<span style="background-color: transparent;">FRANCIS</span>', $nom1));
                $template->setValue('{Nom2}', $nom2);
                $template->setValue('{Nom3}', $nom3);
                $template->setValue('{Tous}', $tous);
                $template->setValue('{To}', $to);
                $template->setValue('{Date}', $date);
                $template->setValue('{Ref}', $ref);
                $template->setValue('{Objet}', $objet);
                $template->setValue('{Body}', $body);
                $template->setValue('{Fonction}', $fonction);
                $template->setValue('{Signataire}', $signataire);

                $filename = 'final.docx';
                $template->saveAs($filename);

                return response()->download($filename);
            } catch (\Throwable $th) {
                throw $th;
            }
<?php

Expected Behavior

Want to get coorect file from TemplateProcessor

Current Behavior

Get Corrupted file after saveAs

Context

Please fill in your environment information:

  • PHP Version:8.2.17
  • PHPWord Version:1.2
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