2
votes

Could you please tell me is it possible to - load docx document into phpword, then change font name, size, line spacing in that loaded document and then save it to another docx file?

I'm reading phpword official docx right now, but as I see it's much more creating a new document (with some font name, size and line spacing trough setting of a paragraph for example) than for changes in loaded document. Or maybe I'm wrong?

So is it possible to change these "font settings" for loaded document? Or maybe it is possible to some parsing of loaded document, like some foreach for all paragraphs and then change "font settings" for every paragraph of text?

Thank you in advance for your help!

Sincerelly yours,

Alwesu

1
point number 4 github.com/PHPOffice/PHPWord read the features herePardeep Poria
Thank you but default font style is for creating someting in new phpword object as I understand. I've tried to change default font name and size, but it's not chainging text in loaded document (but if we add something to loaded document, it'll be in format of default font size and name etc).AlWeSu

1 Answers

7
votes

Yep, changing some of the document default settings is possible. For example changing the default font definitions:

$phpWord = \PhpOffice\PhpWord\IOFactory::load('myfile.docx');
$phpWord->setDefaultFontSize(50);
$phpWord->setDefaultFontName('courier');

for line spacing you can check whether the default value can be modified with the setDefaultParagraphStyles method.