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

Docx is not converted well #2485

Open TheArKaID opened 11 months ago

TheArKaID commented 11 months ago

Describe the Bug

I'm not sure how to describe it, but the generated document is broken (literally not looks like the source document (.docx).

Steps to Reproduce

Please provide a code sample that reproduces the issue.

     $reader = \PhpOffice\PhpWord\IOFactory::createReader('Word2007');
     $phpWord = $reader->load(Storage::disk('document-request')->path($filePath));

     // Docx to Docx
     \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007')->save(Storage::disk('document request')->path($documentRequest->id . '/requirements/') . $filename . '.docx');

     // To PDF (dompdf and tcpdf)
     \PhpOffice\PhpWord\Settings::setPdfRenderer(\PhpOffice\PhpWord\Settings::PDF_RENDERER_DOMPDF, base_path('vendor/dompdf/dompdf'));
     \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'PDF')->save(Storage::disk('document-request')->path($documentRequest->id . '/requirements/') . $filename . '.pdf');

Expected Behavior

Generated looks like the source file.

Current Behavior

Generated files broken-structured.

Context

Please fill in your environment information:

Compared file

The source file was only 1 pages, but pdf resulted in 3 pages. The other file is 2 pages and turn into 5 pages.

Here's the example file I used

allestaire commented 11 months ago

Try using mpdf, but still I dont assure that it will get the exam result when converted to PDF. But mpdf got better result rather that DomPDF

TheArKaID commented 11 months ago

Try using mpdf, but still I dont assure that it will get the exam result when converted to PDF. But mpdf got better result rather that DomPDF

It's better, but still not in accordance with image

allestaire commented 11 months ago

Thats the problem their, mpdf onlt reduce errors but not 100% accurate.