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

Document distorted after set meta info #477

Open
taylorren opened this issue Feb 3, 2015 · 13 comments
Open

Document distorted after set meta info #477

taylorren opened this issue Feb 3, 2015 · 13 comments

Comments

@taylorren
Copy link

taylorren commented Feb 3, 2015

I am exporting a docx file with some input from a form submission.

  1. Load form submission data;
  2. Create a template processor on file "template.docx" to replace ${xxxx} notations with user input. Save the template to "output.docx" (so far this is OK and the format, output is retained).
  3. Open that "output.docx" file, set headers (meta information like creator, subject etc). Save the file to "output2.docx". This is where the output gets distorted. (See attached screen shot). But the meta data has been updated.

The code is excerpted below.

Am I missing something? It works fine with previous release of PHPWord lib but not this one.

ashampoo_snap_2015 02 04_07h22m56s_005_

    public function export($app, Request $req)
    {
        //Grab the POST data
        $info=$this->getInput($req);

        //require_once __DIR__ . '/PHPWord/src/PhpWord/Autoloader.php';
        Autoloader::register();
        Settings::loadConfig();

        $template = new \PhpOffice\PhpWord\TemplateProcessor(__DIR__ . "/template/template.docx");

        $this->setContent($template, $info);

        $template->saveAs(__DIR__ . "/template/output.docx");

        $wadoc=$this->openDoc();

        $this->setHeader($wadoc, $info);

        $fn="/template/output2.docx";
        $wadoc->save(__DIR__.$fn, 'Word2007');

        return $app['twig']->render('done.html.twig', array('link'=>$fn));
    }

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@nafwa03
Copy link

nafwa03 commented Feb 4, 2015

There is definitely a w:p problem going on. What version of Windows are you using?

@taylorren
Copy link
Author

@nafwa03 I am running Windows 8.1 Pro 64 bit and Office 2013. All patched to the latest updates.

@nafwa03
Copy link

nafwa03 commented Feb 4, 2015

I am not one of the dev but have been heavily invested in a project at which I went full with this lib. The latest update has been tough. 2013 should be compat. What has helped me to debug is this:

Generate the docx using the old version... Save it and rename extension to .zip. Extract.

Generate with new version of phpword and do the same.

Run a diff to compare the document.xml files. I use winmerge. Find the differences and then hack where you need to in php word.

Otherwise revert to the old version that worked. Best strategy to me...

@taylorren
Copy link
Author

@nafwa03 Thanks for the hint. That does not help in my case: I am writing an article for Sitepoint. Can't put up an article with "hack" style of code.

@nafwa03
Copy link

nafwa03 commented Feb 4, 2015

Oh I feel you...my bad. I know not a hint ;). Just trying to help.

@nafwa03
Copy link

nafwa03 commented Feb 4, 2015

Just revert back to original before they brought .doc back into the mix.

@taylorren
Copy link
Author

No comments from the development team so far?

@taylorren
Copy link
Author

Still no comment from the development team?

@taylorren
Copy link
Author

Any comments????

@taylorren
Copy link
Author

Still no comments? Or even can't be reproduced?

@xjdata
Copy link

xjdata commented Apr 28, 2016

这还是英文,我的应用中中英混合的.换行更是厉害,彻底看不成.

呃... 我提出问题1年了. 一样没有相应. 估计不会被解决了...

@christopher-francisco
Copy link

Any updates with this? My document is getting distorted; but I'm using DocProperty fields, so that could be it(?)

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@github-actions github-actions bot added the Stale label Nov 18, 2022
@Progi1984 Progi1984 removed the Stale label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants