Skip to content

Text aligment JUSTIFY not wokring in Microsoft Word #2628

Open
@FaheemKGNINFOTECH

Description

@FaheemKGNINFOTECH

Describe the bug and add attachments

when setting

$paragraphStyle = [
                'alignment' => Jc::JUSTIFY,
                'spaceBefore' => Converter::pointToTwip(5),
                'spaceAfter' => Converter::pointToTwip(5),
                'lineHeight' => 1.0
            ];

alignment JUSTIFY then the word file is not opening
phpword

Expected behavior

It should open in microsoft word also like WPS

Steps to reproduce

use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\Shared\Converter;

$phpWord = new PhpWord();

            $fontStyle = ['name' => 'Arial', 'size' => 12];
            $paragraphStyle = [
                'alignment' => Jc::JUSTIFY,
                'spaceBefore' => Converter::pointToTwip(5),
                'spaceAfter' => Converter::pointToTwip(5),
                'lineHeight' => 1.0
            ];

            $section = $phpWord->addSection();
            $section->addText('Remember, exact vertical centering in PHPWord may vary depending on the content size and the overall cell height set.	Remember, exact vertical centering in PHPWord may vary depending on the content size and the overall cell height set.	', $fontStyle, $paragraphStyle);


            // Force download
            header("Content-Description: File Transfer");
            header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
            header('Content-Disposition: attachment; filename="text_justify.docx"');

            header('Cache-Control: max-age=0');
            header('Pragma: public');

            // Create a temporary file in the system's temporary directory
            $tempFile = tempnam(sys_get_temp_dir(), 'phpword');
            $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
            $objWriter->save($tempFile);

            // Download the file
            readfile($tempFile);
            unlink($tempFile); // Delete the temp file after downloading
            exit;

PHPWord version(s) where the bug happened

"phpoffice/phpword": "^1.2",

PHP version(s) where the bug happened

"php": "^8.1",

Priority

  • I want to crowdfund the bug fix (with @algora-io) and fund a community developer.
  • I want to pay the bug fix and fund a maintainer for that. (Contact @Progi1984)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions