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

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

Open Asmitta-01 opened 1 year ago

Asmitta-01 commented 1 year ago

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

Asmitta-01 commented 1 year ago

Up

joaovictormacedo commented 10 months ago

Up

Progi1984 commented 8 months ago

@Asmitta-01 Have you the sample pdf file?

Asmitta-01 commented 7 months ago

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