A Minimal PDF to Image Converter using PHP MuPDF Package

A Minimal PDF to Image Converter using PHP MuPDF Package cover image

This package offers a minimal PDF to image converter using MuPDF. It is heavily inspired by spatie/image-to-pdf.

Installation

You can install this package via Composer.

$ composer require karkowg/php-mupdf

Usage

Convert all the pages to jpg

$pdf = new Karkow\MuPdf\Pdf('path/to/pdf/file');

$pdf->saveAllPagesAsImages('./images/', 'page-');

Convert a single page to png

$pdf = new Karkow\MuPdf\Pdf('path/to/pdf/file');

$pdf
    ->setPage(2)
    ->setOutputFormat('png')
    ->saveImage('./images/page-2.png');

Please refer to tests/PdfTest.php for other use cases.

mutool

A compiled binary (v1.20.0) is available at bin/mutool. If for any reason you want/need to use your own installation, you can do so by passing its path as a 2nd argument to the constructor.

$pdf = new Karkow\MuPdf\Pdf('path/to/pdf/file', 'path/to/mutool');

For more details, Visit Github.

Written by

Rizwan Aslam

Founder and CEO of CodeBrisk, with years of experience building web applications with Laravel and leading a team of expert developers.

More about Rizwan
Book a free call
Book a call with CodeBrisk