PHP code example of ottosmops / pdftothumb

1. Go to this page and download the library: Download ottosmops/pdftothumb library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ottosmops / pdftothumb example snippets


  \Ottosmops\Pdftothumb\Converter::create('/path/to/file.pdf')->convert();
  //creates a thumb of the first page: '/path/to/file.jpg'

$exitCode = (new Converter($source, $target, $executable))->convert();

$converter = Converter::create($source);
$converter->convert()

Converter::create('/path/to/source.pdf')
                 ->target('/path/to/target.jpg')
                 ->executable('path/to/pdftoppm')
                 ->format('jpeg') // jpeg | png | tiff
                 ->scaleTo(150)
                 ->page(1) // or ->firstpage(1)->lastpage(1)
                 ->convert();

Converter::create('/path/to/source.pdf')
                ->addOption('-gray')
                ->convert();

Converter::create('/path/to/source.pdf')
                ->setOptions('-f 3 -l 3 -scale-to 200 -png')
                ->convert();

/*
* These generators will be used to created conversion of media files.
*/
'image_generators' => [
	Spatie\MediaLibrary\ImageGenerators\FileTypes\Image::class ,
	//Spatie\MediaLibrary\ImageGenerators\FileTypes\Pdf::class ,
	Spatie\MediaLibrary\ImageGenerators\FileTypes\Svg::class ,
	Spatie\MediaLibrary\ImageGenerators\FileTypes\Video::class ,
],



namespace App\ImageGenerators;

use Illuminate\Support\Collection;
use Spatie\MediaLibrary\Conversion\Conversion;
use Spatie\MediaLibrary\ImageGenerators\BaseGenerator;
use Ottosmops\Pdftothumb\Converter;

class Pdf extends BaseGenerator
{
   /**
    * This function should return a path to an image representation of the given file.
    */
    public function convert(string $path, Conversion $conversion = null) : string
    {
        $imageFile = pathinfo($path, PATHINFO_DIRNAME).'/'.pathinfo($path, PATHINFO_FILENAME).'.jpg';

        Converter::create($path)->target($imageFile)->convert();

        return $imageFile;
    }

    public function 
which pdftoppm