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

Created on 14 August 2023, over 1 year ago
Updated 20 August 2023, over 1 year 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

Production build 0.71.5 2024