Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Asmitta-01 opened this issue Aug 18, 2023 · 4 comments
Open

Comments

@Asmitta-01
Copy link

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
Copy link
Author

Up

1 similar comment
@joaovictormacedo
Copy link

Up

@Progi1984
Copy link
Member

@Asmitta-01 Have you the sample pdf file?

@Asmitta-01
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants