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

Read and rewrited word2007 document and original document have a lot of differents #620

Open
dmitryfar opened this issue Sep 11, 2015 · 12 comments

Comments

@dmitryfar
Copy link

dmitryfar commented Sep 11, 2015

When I read docx and then save it, it doesn't look like original document. It has no equal styles for text block and tables and there are new line breaks.
Example with simple tables:

    $objReader = \PhpOffice\PhpWord\IOFactory::createReader('Word2007');
    $phpWord = $objReader->load("with_table_macros.docx");

    $phpWord->save("re_with_table_macros.docx");

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

@kichetof
Copy link

Same bug:

$filling = new \PhpOffice\PhpWord\TemplateProcessor($template); // $template file is docx
$filling->setValue('foo', 'bar');
$filling->saveAs($tempFile); // Save as docx, match perfectly

// Opening $tempFile (docx) to export in PDF (and in Word2007, html and odt to test)
phpWord = \PhpOffice\PhpWord\IOFactory::load($tempFile, "Word2007");
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'PDF');
$xmlWriter->save($finalPDF);

$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$xmlWriter->save($finalWord);

unlink($tempFile);

Regardless of the exported format, the document loses its formatting (it's not the PDF lib) :

  • No header
  • No footer
  • No tabulations
  • No text style

It seems that the save processus for \PhpOffice\PhpWord\IOFactory::createWriter isn't the same that \PhpOffice\PhpWord\TemplateProcessor save processus.

My template filled is exactly the same and match perfectly! :)

Hopefully a fix soon :)
Many thanks guys!

PHPWord version dev-master 38cb04d

@Paperclip-Systems
Copy link

I don't know if the problem I was having was the same as this but this fixed the problem for me

#1043

@Piuliss
Copy link

Piuliss commented Dec 19, 2017

I have the same problem

$PHPWord = \PhpOffice\PhpWord\IOFactory::load($filePath, "Word2007");
$sections = $PHPWord->getSections();
foreach ($sections as $section){
			// Add footer
			$footer = $section->addFooter();
			$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align'=>'center'));
}
$PHPWord->save($filePath);

this is changing completly the file, and all the style are missed. The footer is added

@troosan
Copy link
Contributor

troosan commented Dec 19, 2017

@Piuliss @kichetof please try with the dev-develop, parsing of docx document has been improved.

@Piuliss
Copy link

Piuliss commented Dec 20, 2017

should I link to develop repo to composer?
because
composer require phpoffice/phpword:dev-develop
it is not working

@Piuliss
Copy link

Piuliss commented Dec 27, 2017

@troosan finally I could install dev-develop version. Well, now styles look much better, but still are not perfect. Specially with margin and font sizes. I will take look in the code if I can fix it. Thanks.

@cubicleWar
Copy link

@troosan I am using dev-develop and still experiencing this bug. The template processor can open and save the file without issues but using IOFactory causes the loss of all images, styles and header/footer formatting.

@jacklove2run
Copy link

I also have this problem. Using IOFactory to load a .docx file and wanted to save it into type of html, but lost all the images. Dose this problem solved?

@Piuliss
Copy link

Piuliss commented Mar 28, 2018 via email

@jacklove2run
Copy link

@Piuliss OK thanks i'll try developer version later but can u tell me what library u are using now?

@ammarax
Copy link

ammarax commented May 15, 2020

No one fixed this?? is possible that nobody create an exporter from 2017 to 2020 from word to PDF starting from template object??

@baonguyen91hnx
Copy link

I also have this problem. Using IOFactory to load a .docx file and wanted to save it into pdf but lose all my style and formatting :(

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

9 participants