PHPackages                             ottosmops/pdftothumb - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. ottosmops/pdftothumb

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

ottosmops/pdftothumb
====================

Convert PDF to an image

v2.0.2(5y ago)511.2k—0%1MITPHPPHP &gt;=7.2.0

Since May 9Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ottosmops/pdftothumb)[ Packagist](https://packagist.org/packages/ottosmops/pdftothumb)[ Docs](https://github.com/ottosmops/pdftothumb)[ RSS](/packages/ottosmops-pdftothumb/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (2)Versions (6)Used By (0)

Convert a PDF to an image with pdftoppm
=======================================

[](#convert-a-pdf-to-an-image-with-pdftoppm)

[![GitHub license](https://camo.githubusercontent.com/49b3c9039c192e9f9f1662fc16d02e4103a91f03e4c6a9c8f850560c053bdf53/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f74746f736d6f70732f706466746f7468756d622e737667)](https://github.com/ottosmops/pdftothumb/blob/master/LICENSE.md)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7596fa417cac6a49a7ffb26a94f06131439f059200a40522a7ee9f644845bd65/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f74746f736d6f70732f706466746f7468756d622f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ottosmops/pdftothumb/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/733ce0181f14f1ad1d7ca0bbad3b67884331473a81cbf04cb2d2dc3be19945ac/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f74746f736d6f70732f706466746f7468756d622f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ottosmops/pdftothumb/?branch=master)[![Build Status](https://camo.githubusercontent.com/cd65229c6cffca6dce2f5bb5aba10b9a48039f160bed99490c71d88816d64885/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f74746f736d6f70732f706466746f7468756d622f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ottosmops/pdftothumb/build-status/master)[![Latest Stable Version](https://camo.githubusercontent.com/d186320bb8ead49ceab54e855363663cd8d2bfe56247821bcab6f4aeac78db4e/68747470733a2f2f706f7365722e707567782e6f72672f6f74746f736d6f70732f706466746f7468756d622f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/ottosmops/pdftothumb)[![Packagist Downloads](https://camo.githubusercontent.com/2d212f9578008b9f8afefae4f0bbf410acecf5f797589fe68196a1e5ee1e9bce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f74746f736d6f70732f706466746f7468756d622e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ottosmops/pdftothumb)

This package provides a wrapper for `pdftoppm`.

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

We use this as an alternative to the excellent [spatie/pdf-to-image](https://github.com/spatie/pdf-to-image) package as we sometimes have large PDFs to convert and then it seems to be faster and more memory friendly to use pdftoppm.

Requirements
------------

[](#requirements)

The Package uses [pdftoppm](https://linux.die.net/man/1/pdftoppm). Make sure that this is installed: `which pdftoppm`

For Installation see: [poppler-utils](https://linuxappfinder.com/package/poppler-utils)

If the installed binary is not found ("`The command "which pdftoppm" failed.`") you can pass the full path to the `_constructor` (see below) or use `putenv('PATH=$PATH:/usr/local/bin/:/usr/bin')` (with the dir where pdftoppm lives) before you call the class `Converter`.

Installation
------------

[](#installation)

```
composer require ottosmops/pdftothumb
```

Usage
-----

[](#usage)

Converting PDF to jpg:

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

`$target` and `$executable` are optional.

Or like this:

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

You can set some options:

```
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();
```

You can add options:

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

Or you can replace all options and set them by hand:

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

Default options are: `-f 1 -l 1 -scale-to 150 -jpeg`

Usage for spatie/medialibrary
-----------------------------

[](#usage-for-spatiemedialibrary)

Tell the medialibrary not to use the standard ImageGenarator.

config/medialibrary.php

```
/*
* 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 ,
],
```

Create a new ImageGenerator

app/ImageGenarators/Pdf.php

```
