PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.21k stars 2.68k forks source link

Paragraph Indent Units #507

Open jelofson opened 9 years ago

jelofson commented 9 years ago

Hello, I am confused about the paragraph style indent units. The docs say that the defaults measurement units are twips, which is fine, but when adding an indent value to a paragaraph style, they are not in twips. The value set is multiplied by 720. So, if I enter a value of 4, it comes out as 2880 twips, or 2 inches (5.08 cm). Why not just use twips? Then one could use the converters.

https://github.com/PHPOffice/PHPWord/blob/3f136501b3dfea94766a704e17782c8a942a7b9b/src/PhpWord/Style/Paragraph.php#L181

$phpWord->addTitleStyle(1, [
    'size'=>22,
    'color'=>'194775',
    'bold'=>true,
    'name'=>'Cambria',
    'allCaps'=>true
], [
    'align'=>'right',
    'indent'=>4 // 2880 twips = confusion
]);

Comments?

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/9764798-paragraph-indent-units?utm_campaign=plugin&utm_content=tracker%2F323108&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F323108&utm_medium=issues&utm_source=github).
aoloe commented 8 years ago

looks even weirder here... is it using half inches?

drps commented 1 year ago

i can confirm the issue.

Sample code without any changes made by custom code, only read and write operations (you need to specify paragraph's indent in sample docx file)

$phpWord = \PhpOffice\PhpWord\IOFactory::load($tempFile);
$phpWord->save('sample.docx', 'Word2007', true);