PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

Text zones destroyed and Text aligned to the left on pdf conversion

Open Asmitta-01 opened this issue 1 year ago • 4 comments

Describe the Bug

When i convert a file(docx) to pdf the text zones inside the document are "destroyed" and the content of these zones is on the the top of the document, left aligned.

Steps to Reproduce

This is my class"

<?php

require __DIR__ . '/../vendor/autoload.php';

use PhpOffice\PhpWord\IOFactory;
use PhpOffice\PhpWord\Settings;

class WordToPdf
{

    public function __construct(
        private string $file_path
    ) {
    }

    public function toPDF(): bool
    {
        Settings::setPdfRendererName(Settings::PDF_RENDERER_MPDF);
        Settings::setPdfRendererPath('.');

        if (file_exists($this->file_path) && pathinfo($this->file_path, PATHINFO_EXTENSION) == 'docx') {
            $phpWord = IOFactory::load($this->file_path, 'Word2007');
            $phpWord->save(str_replace('.docx', ".pdf", $this->file_path), 'PDF');

            return true;
        }
        return false;
    }
}

Expected Behavior

What i have : https://ibb.co/8xSJkzd, what i want (the original word): https://ibb.co/6NPDSht.

Context

  • PHP Version: 8.2
{
    "require": {
        "mpdf/mpdf": "^8.1",
        "phpoffice/phpword": "^1.1"
    }
}

Asmitta-01 avatar Aug 18 '23 10:08 Asmitta-01

Up

Asmitta-01 avatar Aug 29 '23 08:08 Asmitta-01

Up

joaovictormacedo avatar Oct 28 '23 00:10 joaovictormacedo

@Asmitta-01 Have you the sample pdf file?

Progi1984 avatar Dec 25 '23 08:12 Progi1984

RH-RECRUT002 - LETTRE DE MOTIVATION - SENIOR 2 - Offre d'emploi publiée.docx There is a word file that i'm trying to convert.

Asmitta-01 avatar Jan 23 '24 00:01 Asmitta-01