PHPWord
PHPWord copied to clipboard
Text zones destroyed and Text aligned to the left on pdf conversion
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"
}
}
Up
Up
@Asmitta-01 Have you the sample pdf file?
RH-RECRUT002 - LETTRE DE MOTIVATION - SENIOR 2 - Offre d'emploi publiée.docx There is a word file that i'm trying to convert.