zainul's avatar
Level 1

phpoffice/phpword generate broken format for pdf files

After I successfully upgraded my project from laravel 5 to laravel 9, there is issue with pdf generator. The pdf generated in broken format. Originally, the pdf generator should follow the format from the Word file after generate to pdf but now it produce a broken format pdf file.

So should I working on fixing the code? Or should I working on fixing the phpoffice/phpword dependency files?

Below are the codes for the pdf generator:

SchemeController.php

app\Libs\Template\Template.php

app\Libs\PDF\WordReplacer.php

<?php

namespace App\Libs\PDF;

use Illuminate\Support\Str;
use PhpOffice\PhpWord\Settings;
use Illuminate\Support\Facades\File;
use PhpOffice\PhpWord\TemplateProcessor;

class WordReplacer
{

//other codes

    public function replaceAndConvert($inputFile, $outputDir, $replaceValues = [])
    {
        $tempFile = $this->replace($inputFile, $outputDir, $replaceValues);

        $outputFile = $this->converter->convert($tempFile, $outputDir);

        File::delete($tempFile);

        return $outputFile;
    }

//other codes

}

composer.lock

            "name": "phpoffice/phpword",
            "version": "0.18.3",
            "source": {
                "type": "git",
                "url": "https://github.com/PHPOffice/PHPWord.git",
                "reference": "be0190cd5d8f95b4be08d5853b107aa4e352759a"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/PHPOffice/PHPWord/zipball/be0190cd5d8f95b4be08d5853b107aa4e352759a",
                "reference": "be0190cd5d8f95b4be08d5853b107aa4e352759a",
                "shasum": ""
            },

composer.json

    "require": {
        "php": "^8.0",
        "ext-json": "*",
        "artisaninweb/laravel-soap": "0.3.0.9",
        "barryvdh/laravel-debugbar": "^3.6",
        "barryvdh/laravel-dompdf": "^1.0",
        "davejamesmiller/laravel-breadcrumbs": "^5.3",
        "doctrine/dbal": "^2.13",
        "eduardokum/laravel-mail-auto-embed": "^2.10",
        "guzzlehttp/guzzle": "^7.2",
        "jaspersoft/rest-client": "^2.0",
        "laravel/framework": "^9.52",
        "laravel/tinker": "^2.7",
        "laravel/ui": "^3.3",
        "league/csv": "^9.6",
        "league/flysystem-aws-s3-v3": "^3.27",
        "maatwebsite/excel": "^3.1",
        "phpoffice/phpword": "0.18.3",
        "predis/predis": "^1.1",
        "spatie/laravel-ignition": "^1.4",
        "spatie/laravel-permission": "^5.5",
        "webklex/laravel-pdfmerger": "^1.3"
    },
0 likes
0 replies

Please or to participate in this conversation.