Fax download error after patch 3

Sorry for the multiple posts here after patch 3. Some were my error with a disk volume storage. However, when trying to download a fax as pdf i get error Failed to display the document due to an invalid document format. Also previously I had some documents in the patient document folders in jpg format that kick out an error that I can start another thread. The logs for the file format for faxes is listed here.

Situation
As above
OpenEMR Version
7.0.2 p3
Browser:
I’m using:
Chrome
Operating System
I’m using:
Ubuntu 22 LTS
Search
Yest
Logs
Did you check the logs?

[Tue Nov 26 11:52:42.011157 2024] [php:error] [pid 1045755] [client 72.206.76.140:39172] PHP Fatal error:  Uncaught TypeError: OpenEMR\\Services\\ImageUtilities\\HandleImageService::convertImageToPdfUseImagick(): Return value must be of type string|false, null returned in /var/www/xxx/openemr/src/Services/ImageUtilities/HandleImageService.php:93\nStack trace:\n#0 /var/www/xxx/openemr/src/Services/ImageUtilities/HandleImageService.php(279): OpenEMR\\Services\\ImageUtilities\\HandleImageService->convertImageToPdfUseImagick('...', '')\n#1 /var/www/xxx/openemr/interface/modules/custom_modules/oe-module-faxsms/src/Controller/EtherFaxActions.php(556): OpenEMR\\Services\\ImageUtilities\\HandleImageService->convertImageToPdf('...', '')\n#2 /var/www/xxx/openemr/interface/modules/custom_modules/oe-module-faxsms/src/Controller/EtherFaxActions.php(524): OpenEMR\\Modules\\FaxSMS\\Controller\\EtherFaxActions->formatFax('...')\n#3 [internal function]: OpenEMR\\Modules\\FaxSMS\\Controller\\EtherFaxActions->viewFax(Array)\n#4 /var/www/xxx/openemr/interface/modules/custom_modules/oe-module-faxsms/src/Controller/AppDispatch.php(79): call_user_func(Array, Array)\n#5 /var/www/xxx/openemr/interface/modules/custom_modules/oe-module-faxsms/src/Controller/AppDispatch.php(52): OpenEMR\\Modules\\FaxSMS\\Controller\\AppDispatch->dispatchActions()\n#6 /var/www/xxx/openemr/interface/modules/custom_modules/oe-module-faxsms/src/Controller/EtherFaxActions.php(55): OpenEMR\\Modules\\FaxSMS\\Controller\\AppDispatch->__construct()\n#7 /var/www/xxx/openemr/interface/modules/custom_modules/oe-module-faxsms/src/Controller/AppDispatch.php(238): OpenEMR\\Modules\\FaxSMS\\Controller\\EtherFaxActions->__construct()\n#8 /var/www/xxx/openemr/interface/modules/custom_modules/oe-module-faxsms/src/Controller/AppDispatch.php(200): OpenEMR\\Modules\\FaxSMS\\Controller\\AppDispatch::getServiceInstance('...')\n#9 /var/www/xxx/openemr/interface/modules/custom_modules/oe-module-faxsms/index.php(25): OpenEMR\\Modules\\FaxSMS\\Controller\\AppDispatch::setApiService('...')\n#10 {main}\n  thrown in /var/www/xxx/openemr/src/Services/ImageUtilities/HandleImageService.php on line 93, referer: https://xxx/interface/modules/custom_modules/oe-module-faxsms/messageUI.php?type=fax

Was there anything pertinent in them?
Please paste them here (surround with three backticks (```) for readability.
You can also turn on User Debugging under Administration->Globals->Logging User Debugging Options=>All

There have been no changes to etherfax in patch 3.
It looks like Imagick is being used so you have the imagick extension installed and enabled.
There are three was I try to resolve tiff images to pdf. 1. imagick(first choice) 2.gd 3. Javascript routines I developed.

If neither imagick or gd are installed I auto to using Javascript.
I’ve never tested the linux imagick. Works great on windows.

Php -m to check installed extensions.

Yes I have imagick installed because I use the scans function under miscellaneous tabs. How would I configure to use imagick for the fax sms module or does the code go down your order to try to use a conversion program. If its using imagick, which it appears it is, then how would i resolve the HandleImageService::convertImageToPdfUseImagick(): Return value must be of type string|false, null returned error. I have not had issues with imagick until now.

Todd

Or could I hard code the module to use Javascript instead of imagick? Im assuming thats removing theme from the module code. Let me know if im on the right track.

Todd

yes. it’s unfortunate imagick doesn’t work but I actually spent a lot of time to avoid using any extension but forgot to remove the code for extensions.
Goto:

src/Services/ImageUtilities/HandleImageService.php around L-260
 public function convertImageToPdf($imageData, $pdfPath = '', $useExt = 'gd'): false|string
    {
        $content = '';
        return false;

just add a return false; at top then if you want you can delete the rest of method code.

Thanks Jerry,

I simply changed imageick to gd and left the rest of the code alone and it works now.

code is as follows starting on line 260:

    {
        $content = '';

        if (is_file($imageData)) {
            $imageContent = file_get_contents($imageData);
        } else {
            $imageContent = $imageData;
        }
        // Check for extension availability
        $usingImagick =  $this->isImagickAvailable() && $useExt === 'imagick';
        $usingGd =  $this->isGdAvailable() && $useExt === 'gd' && !$usingImagick;

        if (!$usingImagick && !$usingGd) {
            return false; // todo Could provide an alternative method but JS will pick this up
        }

        try {
            if ($usingImagick) {
                $content = $this->convertImageToPdfUseImagick($imageContent, $pdfPath);
            } elseif ($usingGd) {
                // Implement GD conversion or provide a message if not yet implemented
                $content = false; // Placeholder for actual GD implementation
                error_log('GD based conversion not implemented.');
            }
        } catch (Exception $e) {
            error_log('Error converting image to PDF using ' . ($usingImagick ? 'Imagick' : 'GD') . ': ' . text($e->getMessage()));
            return false;
        }

        return $content;
    }
}```

sorry it was incomlete.

public function convertImageToPdf($imageData, $pdfPath = '', $useExt = 'gd'): false|string
{
    $content = '';

    if (is_file($imageData)) {
        $imageContent = file_get_contents($imageData);
    } else {
        $imageContent = $imageData;
    }
    // Check for extension availability
    $usingImagick =  $this->isImagickAvailable() && $useExt === 'imagick';
    $usingGd =  $this->isGdAvailable() && $useExt === 'gd' && !$usingImagick;

    if (!$usingImagick && !$usingGd) {
        return false; // todo Could provide an alternative method but JS will pick this up
    }

    try {
        if ($usingImagick) {
            $content = $this->convertImageToPdfUseImagick($imageContent, $pdfPath);
        } elseif ($usingGd) {
            // Implement GD conversion or provide a message if not yet implemented
            $content = false; // Placeholder for actual GD implementation
            error_log('GD based conversion not implemented.');
        }
    } catch (Exception $e) {
        error_log('Error converting image to PDF using ' . ($usingImagick ? 'Imagick' : 'GD') . ': ' . text($e->getMessage()));
        return false;
    }

    return $content;
}

}

That’ll work too!
The only reason those extensions are needed is to deal with tiff images.
I believe I need to keep them in thought I have a JS solution perhaps for Patient Documents so I guess I’ll add a Config item to select which to use.
I’m curious why works on window but not linux but for another day.:slight_smile:

Glad you’re working.

Odd that imagick doesnt work either. Usually its more of a pain to install on windows and more functional on linux. Its a great module and I appreciate your work.

On a site note, for the module, when sending faxes it ties up the system while its transmitting the file to etherfax or other service. As an added feature it would be nice to be able to send the fax and have it go to an outbound que and process in the background if possible.

Happy holidays

Todd

1 Like