Generating a PDF Thumbnail in PHP can be a requirement for many developers when they work on some document management system, e-learning tool, or even file upload module. The thumbnail gives the user an instant idea regarding the content of the PDF. This guide describes how to generate thumbnails with PHP and Imagick in a clean and easy way while maintaining everything beginner-friendly.
PDF thumbnails allow users to quickly identify documents. They enhance user experience in file browsing interfaces, digital libraries, invoice systems, and customer portals by allowing users to save time and avoid unnecessary clicks.
Prerequisites Imagick for PDF Thumbnail in PHP
To create a PDF thumbnail in PHP, you need to install Imagick on your server or local environment. It reads the PDF and converts it into an image. Most of the hosting services allow it, and you can enable it easily when setting up locally or check if already installed using php info function.

Generate PDF Thumbnail in PHP Example
Generating thumbnail from PDF using imagick is quite simple. Let’s see first basic code to create thumbnail then we will move further with PDF upload example.
<?php
$pdfPath = 'sample.pdf';
$thumbnailPath = 'thumbnail.jpg';
$imagick = new Imagick();
$imagick->setResolution(150, 150);
$imagick->readImage($pdfPath . '[0]');
$imagick->setImageFormat('jpg');
$imagick->writeImage($thumbnailPath);
$imagick->clear();
$imagick->destroy();
?>This script reads the first page of a PDF and converts it into a JPEG thumbnail. You can display this image inside dashboards, cards, or any document preview section. You can adjust the resolution based on the quality you want.
It is programmed to read first page and convert it to image for preview. At last, you will store image as jpg file for preview. You can customize this code to generate thumbnail or entire PDF file using loop.
Full Example Upload PDF and Generate Thumbnail in PHP
Below is a simple script where you upload a PDF and it generates a thumbnail instantly. It works well in small tools, admin panels, and file preview apps.
<?php
if (!empty($_FILES["pdf"]["name"])) {
$pdfPath = $_FILES["pdf"]["name"];
move_uploaded_file($_FILES["pdf"]["tmp_name"], $pdfPath);
$thumbnailPath = "thumbnail_" . time() . ".jpg";
$imagick = new Imagick();
$imagick->setResolution(150, 150);
$imagick->readImage($pdfPath . "[0]");
$imagick->setImageFormat("jpg");
$imagick->writeImage($thumbnailPath);
$imagick->clear();
$imagick->destroy();
} ?>
<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light py-5">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card shadow-sm">
<div class="card-body">
<h4 class="mb-4 text-center">Upload PDF to Generate Thumbnail</h4>
<form method="post" enctype="multipart/form-data">
<div class="mb-3">
<label class="form-label">Choose PDF File</label>
<input type="file" name="pdf" class="form-control">
</div>
<button type="submit" class="btn btn-primary w-100">Upload</button>
</form>
<?php if (!empty($thumbnailPath)): ?>
<div class="mt-4 text-center">
<img src="<?php echo $thumbnailPath; ?>" class="img-fluid rounded border">
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>Output:

This script allows you upload a PDF, generates a thumbnail, and displays it on the page. It works well for preview based applications where users want an instant visual output.
Conclusion
A simple PHP setup is all you need to get clean and fast PDF previews. The conversion goes through seamlessly with Imagick, and the thumbnail will improve the experience in any document-driven interface. Use this workflow to create friendlier tools that enable users to go through files more efficiently.
