Skip to content

Docx is not converted well #2485

@TheArKaID

Description

@TheArKaID

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:

  • PHP Version: 8.1
  • PHPWord Version: 1.1
  • Laravel Version: 10
  • Dompdf Version: *Latest
  • TCPDF Version: 6.6.5

Compared file

  • Docx to Docx (This is just a try, and looks like PHPWord cannot read the document even without any change correctly)
    image

  • Docx to PDF (DomPDF and TCPDF return the same-broken structured-result)
    image

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions