error caused by inexistant setLayerMethod in spatie pdf-to-image

Created on 14 August 2023, 11 months ago
Updated 20 August 2023, 10 months ago

Problem/Motivation

The latest spatie/pdf-to-image does not have a setLayerMethod method which causes an error.
Error: Call to undefined method Spatie\\PdfToImage\\Pdf::setLayerMethod()

Steps to reproduce

Install spatie/pdf-to-image with composer (will install the latest) and install the Media PDF Thumbnail module.
Activate the module
Configure a media entry to display its thumbnail as pdf and try to view it

Proposed resolution

comment out or remove the call which is not needed anymore as spatie/pdf-to-image only supports a single layering mode now. this would not work with older versions of spatie pdf-to-image in case the call is mandatory.
Try

if (function_exists("$pdf->setLayerMethod")) {
 // call function
}

I have no idea if function_exists works on functions inside classes (needs testing)

  /**
   * @param $pdf
   * @param $target
   * @param $imageFormat
   * @param $page
   *
   * @return mixed
   */
  protected function generate($pdf, $target, $imageFormat, $page) : mixed {
    $pdf->getNumberOfPages() > intval($page) ? $pdf->setPage(intval($page)) : '';
    //$pdf->setLayerMethod(NULL);
    $pdf->setOutputFormat($imageFormat);
    if (file_exists($target)) {
      $this->fileSystem->delete($target);
    }
    return $pdf->saveImage($target);
  }

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: works as designed

Version

6.0

Component

Code

Created by

πŸ‡±πŸ‡§Lebanon vitch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @vitch
  • πŸ‡±πŸ‡§Lebanon vitch
  • πŸ‡±πŸ‡§Lebanon vitch
  • πŸ‡«πŸ‡·France sgostanyan

    Could you please tell where you find that setLayerMethod has been removed ? It seems to still exists, maybe I have missed something.

    Thanks

  • πŸ‡±πŸ‡§Lebanon vitch

    Hello its my mistake composer automatically installed version 1.2.2 when i thought it would install the latest. it did not exist in that version which i mistakenly assumed was the latest.

  • πŸ‡±πŸ‡§Lebanon vitch

    function_exists does not work for methods I just updated the plugin to v2.2.0 and tested this variant which worked fine:

    	if (method_exists($pdf, 'setLayerMethod') && is_callable([$pdf, 'setLayerMethod'])) {
    		$pdf->setLayerMethod(NULL);
    	}
    
  • Status changed to Closed: works as designed 10 months ago
  • πŸ‡«πŸ‡·France sgostanyan

    The module requires at least spatie/pdf-to-image v1.4.0 for 5.x and v2.1.0 for 6.x. So no needs to update.

    Thanks :)

Production build 0.69.0 2024