{"id":5741,"date":"2024-12-26T18:23:37","date_gmt":"2024-12-26T18:23:37","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=5741"},"modified":"2024-12-26T18:29:25","modified_gmt":"2024-12-26T18:29:25","slug":"generate-thumbnail-from-pdf-using-php","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/","title":{"rendered":"Generate Thumbnail from PDF using PHP"},"content":{"rendered":"<p><b>PDF Thumbnail<\/b> is the best way to display a preview of the PDF document. When you have a media library section in the web application and want to display the PDF preview in a listing, thumbnail images are a great option. In this process, you need to create thumbnail image from PDF document and display this image as a preview.<\/p>\n<p>There are various third-party libraries available to generate thumbnail of PDF. But you can create PDF thumbnails in PHP without using any third-party library. <b>PHP ImageMagick library<\/b> can be used to generate PDF thumbnails in PHP. In this tutorial, we will show you how to generate thumbnail from PDF using PHP.<\/p>\n<p>In this PDF thumbnail generator script, we will use the ImageMagick extension to <b>generate thumbnail images from PDF<\/b> in PHP. Also, we will show how you can upload PDF files and create thumbnails on the fly using PHP.<\/p>\n<h2>ImageMagick Library<\/h2>\n<p>The <code>imagick<\/code> extension must be installed and enabled on the server to make this script work. Check whether the following line is available in the php.ini file.<\/p>\n<pre><span class=\"hljs-attribute\" style=\"font-weight: 700;\">extension<\/span>=php_imagick.dll<\/pre>\n<p>You can also check the availability of the Imagick extension on your server by running the <code>phpinfo()<\/code> command on the browser.<\/p>\n<div class=\"img_center\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/imagick-extension-phpinfo-codexworld.png\" alt=\"imagick-extension-phpinfo-codexworld\" width=\"1227\" height=\"548\" class=\"alignnone size-full wp-image-5742\" srcset=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/imagick-extension-phpinfo-codexworld.png 1227w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/imagick-extension-phpinfo-codexworld-300x134.png 300w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/imagick-extension-phpinfo-codexworld-1024x457.png 1024w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/imagick-extension-phpinfo-codexworld-768x343.png 768w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/imagick-extension-phpinfo-codexworld-350x156.png 350w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/imagick-extension-phpinfo-codexworld-320x143.png 320w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/imagick-extension-phpinfo-codexworld-380x170.png 380w\" sizes=\"auto, (max-width: 1227px) 100vw, 1227px\" \/><\/div>\n<h2>Generate Thumbnail from PDF in PHP<\/h2>\n<p>The following code snippet creates thumbnail image for PDF file using PHP.<\/p>\n<ul>\n<li>Specify the source PDF file from which the thumbnail image will be generated.<\/li>\n<li>Specify the folder path where the PDF thumbnail will be stored.<\/li>\n<li>Initialize the Imagick library and pass the PDF document page number in the Imagick() class.<\/li>\n<li>Set the thumbnail image file type using the setImageFormat() function of the Imagick library.<\/li>\n<li>Set the thumbnail image size using the thumbnailImage() function.<\/li>\n<li>Save image in the directory using the writeImage() function.<\/li>\n<\/ul>\n<pre><span style=\"color: #FF8000\">\/\/&nbsp;Source&nbsp;PDF&nbsp;file <br \/><\/span><span style=\"color: #0000BB\">$pdf_file&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'pdf_files\/Brochure.pdf'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;PDF&nbsp;thumbnail&nbsp;image&nbsp;path <br \/><\/span><span style=\"color: #0000BB\">$thumb_path&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'thumbnails\/pdf-image.jpg'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Generate&nbsp;thumbnail&nbsp;from&nbsp;PDF <br \/><\/span><span style=\"color: #0000BB\">$im&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Imagick<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$pdf_file<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"[0]\"<\/span><span style=\"color: #007700\">);&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;0-first&nbsp;page,&nbsp;1-second&nbsp;page <br \/><\/span><span style=\"color: #0000BB\">$im<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">setImageColorspace<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">255<\/span><span style=\"color: #007700\">);&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;prevent&nbsp;image&nbsp;colors&nbsp;from&nbsp;inverting <br \/><\/span><span style=\"color: #0000BB\">$im<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">setImageFormat<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"jpeg\"<\/span><span style=\"color: #007700\">);&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;file&nbsp;type <br \/><\/span><span style=\"color: #0000BB\">$im<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">thumbnailImage<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">1024<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">1024<\/span><span style=\"color: #007700\">);&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;width&nbsp;and&nbsp;height <br \/><\/span><span style=\"color: #0000BB\">$im<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">writeImage<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$thumb_path<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$im<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">clear<\/span><span style=\"color: #007700\">(); <br \/><\/span><span style=\"color: #0000BB\">$im<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">destroy<\/span><span style=\"color: #007700\">();<\/span><\/pre>\n<h2>Upload PDF File and Create Thumbnail of PDF<\/h2>\n<p>This example code snippet shows you the step-by-step process to upload PDF files and generate thumbnails from PDF using PHP.<\/p>\n<p><b>HTML Form:<\/b><br \/>\nDefine HTML elements for file uploading form.<\/p>\n<pre style=\"color: rgb(95, 94, 78);\"><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">form<\/span> <span class=\"hljs-attr\">action<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"submit.php\"<\/span> <span class=\"hljs-attr\">method<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"post\"<\/span> <span class=\"hljs-attr\">enctype<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"multipart\/form-data\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"form-input\"<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">label<\/span> <span class=\"hljs-attr\">for<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"pdf_file\"<\/span>&gt;<\/span>PDF File<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">label<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"file\"<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"pdf_file\"<\/span> <span class=\"hljs-attr\">placeholder<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"Select a PDF file\"<\/span> <span class=\"hljs-attr\">required<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"submit\"<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"submit\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"btn\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"Create Thumbnail\"<\/span>&gt;<\/span>\r\n<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">form<\/span>&gt;<\/span><\/pre>\n<p>On form submission, the selected file is submitted to the server-side script for process further.<\/p>\n<p><b>Server-side Script (submit.php) to Extract Text from Uploaded PDF:<\/b><br \/>\nThe following code is used to upload the submitted file and generate thumbnail of PDF.<\/p>\n<ul>\n<li>Retrieve file name using $_FILES in PHP.<\/li>\n<li>Get file extension using <code>pathinfo()<\/code> function with the PATHINFO_EXTENSION filter.<\/li>\n<li>Validate the file to check whether it is a valid PDF file.<\/li>\n<li>Retrieve file path using <code>tmp_name<\/code> in $_FILES.<\/li>\n<li>Generate thumbnail of the PDF first page using the Imagick library and save the image in a folder.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/> <br \/>$statusMsg&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>if(isset(<\/span><span style=\"color: #0000BB\">$_POST<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'submit'<\/span><span style=\"color: #007700\">])){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;If&nbsp;file&nbsp;is&nbsp;selected <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(!empty(<\/span><span style=\"color: #0000BB\">$_FILES<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">\"pdf_file\"<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">\"name\"<\/span><span style=\"color: #007700\">])){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;File&nbsp;upload&nbsp;path <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$fileName&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">basename<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$_FILES<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">\"pdf_file\"<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">\"name\"<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$fileType&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">pathinfo<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$fileName<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">PATHINFO_EXTENSION<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Allow&nbsp;certain&nbsp;file&nbsp;formats <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$allowTypes&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;array(<\/span><span style=\"color: #DD0000\">'pdf'<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">in_array<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$fileType<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$allowTypes<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Source&nbsp;PDF&nbsp;file <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$pdf_file&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$_FILES<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">\"pdf_file\"<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">\"tmp_name\"<\/span><span style=\"color: #007700\">]; <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;PDF&nbsp;thumbnail&nbsp;image&nbsp;path <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$thumb_path&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'pdf_thumbnails\/pdf-image.jpg'<\/span><span style=\"color: #007700\">; <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Generate&nbsp;thumbnail&nbsp;from&nbsp;PDF <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$im&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Imagick<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$pdf_file<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"[0]\"<\/span><span style=\"color: #007700\">);&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;0-first&nbsp;page,&nbsp;1-second&nbsp;page <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$im<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">setImageColorspace<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">255<\/span><span style=\"color: #007700\">);&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;prevent&nbsp;image&nbsp;colors&nbsp;from&nbsp;inverting <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$im<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">setImageFormat<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"jpeg\"<\/span><span style=\"color: #007700\">);&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;file&nbsp;type <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$im<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">thumbnailImage<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">1024<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">1024<\/span><span style=\"color: #007700\">);&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;width&nbsp;and&nbsp;height <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$im<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">writeImage<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$thumb_path<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$im<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">clear<\/span><span style=\"color: #007700\">(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$im<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">destroy<\/span><span style=\"color: #007700\">(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$statusMsg&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;p&gt;Sorry,&nbsp;only&nbsp;PDF&nbsp;file&nbsp;is&nbsp;allowed&nbsp;to&nbsp;upload.&lt;\/p&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$statusMsg&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;p&gt;Please&nbsp;select&nbsp;a&nbsp;PDF&nbsp;file&nbsp;to&nbsp;generate&nbsp;thumbnail.&lt;\/p&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>} <br \/> <br \/>echo&nbsp;<\/span><span style=\"color: #0000BB\">$statusMsg<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span><\/pre>\n<h2>Conclusion<\/h2>\n<p>Here we discussed the simple way to create PDF thumbnail image with PHP. You can generate PDF thumbnails in different image formats (JPG, PNG, etc) and sizes. This PDF thumbnail maker script functionality can be enhanced for advanced features.<\/p>\n<p class=\"seeAlso\"><span><\/span><a href=\"https:\/\/www.codexworld.com\/extract-text-from-pdf-using-php\/\">Extract Text from PDF using PHP<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PDF Thumbnail is the best way to display a preview of the PDF document. When you have a media library section in the web application and want to display the PDF preview in a listing, <\/p>\n","protected":false},"author":1,"featured_media":5745,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[166,181,14,387],"class_list":["post-5741","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-library","tag-pdf","tag-php","tag-thumbnail","cat-4-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Generate Thumbnail from PDF using PHP - CodexWorld<\/title>\n<meta name=\"description\" content=\"Generate thumbnail from pdf in PHP - Example code snippet to create thumbnail image of PDF using PHP. Upload PDF file and generate thumbnail preview using Imagick library in PHP.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Generate Thumbnail from PDF using PHP - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"Generate thumbnail from pdf in PHP - Example code snippet to create thumbnail image of PDF using PHP. Upload PDF file and generate thumbnail preview using Imagick library in PHP.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2024-12-26T18:23:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-12-26T18:29:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/generate-thumbnail-from-pdf-using-php-codexworld.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/generate-thumbnail-from-pdf-using-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/generate-thumbnail-from-pdf-using-php\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Generate Thumbnail from PDF using PHP\",\"datePublished\":\"2024-12-26T18:23:37+00:00\",\"dateModified\":\"2024-12-26T18:29:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/generate-thumbnail-from-pdf-using-php\\\/\"},\"wordCount\":469,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/generate-thumbnail-from-pdf-using-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2024\\\/12\\\/generate-thumbnail-from-pdf-using-php-codexworld.png\",\"keywords\":[\"Library\",\"PDF\",\"PHP\",\"Thumbnail\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/generate-thumbnail-from-pdf-using-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/generate-thumbnail-from-pdf-using-php\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/generate-thumbnail-from-pdf-using-php\\\/\",\"name\":\"Generate Thumbnail from PDF using PHP - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/generate-thumbnail-from-pdf-using-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/generate-thumbnail-from-pdf-using-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2024\\\/12\\\/generate-thumbnail-from-pdf-using-php-codexworld.png\",\"datePublished\":\"2024-12-26T18:23:37+00:00\",\"dateModified\":\"2024-12-26T18:29:25+00:00\",\"description\":\"Generate thumbnail from pdf in PHP - Example code snippet to create thumbnail image of PDF using PHP. Upload PDF file and generate thumbnail preview using Imagick library in PHP.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/generate-thumbnail-from-pdf-using-php\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/generate-thumbnail-from-pdf-using-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/generate-thumbnail-from-pdf-using-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2024\\\/12\\\/generate-thumbnail-from-pdf-using-php-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2024\\\/12\\\/generate-thumbnail-from-pdf-using-php-codexworld.png\",\"width\":1920,\"height\":1080,\"caption\":\"generate-thumbnail-from-pdf-using-php-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/generate-thumbnail-from-pdf-using-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Generate Thumbnail from PDF using PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Generate Thumbnail from PDF using PHP - CodexWorld","description":"Generate thumbnail from pdf in PHP - Example code snippet to create thumbnail image of PDF using PHP. Upload PDF file and generate thumbnail preview using Imagick library in PHP.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/","og_locale":"en_US","og_type":"article","og_title":"Generate Thumbnail from PDF using PHP - CodexWorld","og_description":"Generate thumbnail from pdf in PHP - Example code snippet to create thumbnail image of PDF using PHP. Upload PDF file and generate thumbnail preview using Imagick library in PHP.","og_url":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2024-12-26T18:23:37+00:00","article_modified_time":"2024-12-26T18:29:25+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/generate-thumbnail-from-pdf-using-php-codexworld.png","type":"image\/png"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Generate Thumbnail from PDF using PHP","datePublished":"2024-12-26T18:23:37+00:00","dateModified":"2024-12-26T18:29:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/"},"wordCount":469,"commentCount":0,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/generate-thumbnail-from-pdf-using-php-codexworld.png","keywords":["Library","PDF","PHP","Thumbnail"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/","url":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/","name":"Generate Thumbnail from PDF using PHP - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/generate-thumbnail-from-pdf-using-php-codexworld.png","datePublished":"2024-12-26T18:23:37+00:00","dateModified":"2024-12-26T18:29:25+00:00","description":"Generate thumbnail from pdf in PHP - Example code snippet to create thumbnail image of PDF using PHP. Upload PDF file and generate thumbnail preview using Imagick library in PHP.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/generate-thumbnail-from-pdf-using-php-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/generate-thumbnail-from-pdf-using-php-codexworld.png","width":1920,"height":1080,"caption":"generate-thumbnail-from-pdf-using-php-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/generate-thumbnail-from-pdf-using-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Generate Thumbnail from PDF using PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2024\/12\/generate-thumbnail-from-pdf-using-php-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-1uB","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/5741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=5741"}],"version-history":[{"count":3,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/5741\/revisions"}],"predecessor-version":[{"id":5746,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/5741\/revisions\/5746"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/5745"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=5741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=5741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=5741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}