You are here

MediaPdfThumbnailImagickManager.php in Media PDF Thumbnail 8.3

File

src/Manager/MediaPdfThumbnailImagickManager.php
View source
<?php

namespace Drupal\media_pdf_thumbnail\Manager;

use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Spatie\PdfToImage\Pdf;

/**
 * Class MediaPdfThumbnailImagickManager.
 *
 * @package Drupal\media_pdf_thumbnail\Manager
 */
class MediaPdfThumbnailImagickManager {

  /**
   * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
   */
  protected $logger;

  /**
   * MediaPdfThumbnailImagickManager constructor.
   *
   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerChannel
   */
  public function __construct(LoggerChannelFactoryInterface $loggerChannel) {
    $this->logger = $loggerChannel
      ->get('Media PDF Thumbnail');
  }

  /**
   * Generate image from PDF file.
   *
   * @param string $source
   *   File source.
   * @param string $target
   *   File target.
   *
   * @return string
   *   File path.
   *
   */
  public function generateImageFromPDF($source, $target) {
    try {
      $pdf = new Pdf($source);
      $pdf
        ->saveImage($target);
    } catch (\Exception $e) {
      $this->logger
        ->error($e
        ->getMessage());
      return FALSE;
    }
    return TRUE;
  }

}

Classes

Namesort descending Description
MediaPdfThumbnailImagickManager Class MediaPdfThumbnailImagickManager.