5

I have file module, where I want to list all files,with thumbnail preview.

as like follows,

enter image description here

I am storing files in storage folder,which is not accessible via http.

So How can I provide thumbnail preview for docs especially image and PDF.

Is there any package availabe in laravel 5.1?

gsk
  • 2,329
  • 8
  • 32
  • 56
  • You may not find a Laravel-specific answer, but there's plenty of PHP answers to this. See [this one](http://stackoverflow.com/questions/467793/how-do-i-convert-a-pdf-document-to-a-preview-image-in-php) for example. – Simba Sep 17 '15 at 12:42
  • 1
    but getting very difficulty to install and make work `imagick` on windows.. – gsk Sep 17 '15 at 13:37
  • Hmm, my first reaction is that you shouldn't be running PHP on Windows! But I know imagemagick can run on Windows. I googled for you; here's one result I found: http://stackoverflow.com/questions/20976779/how-to-install-imagemagick-to-use-with-php-on-windows-7-3. But in any case, the question I linked above also includes answers that don't require imagemagick. – Simba Sep 17 '15 at 13:45

2 Answers2

11

The preview image of a PDF file is usually the first page of the PDF file.

You can use ImageMagick to obtain that first page of the PDF file.

<?php
$imagick = new imagick('sample.pdf[0]'); // 0 specifies the first page of the pdf

$imagick->setImageFormat('jpg'); // set the format of the output image
header('Content-Type: image/jpeg'); // set the header for the browser to understand
echo $imagick; // display the image
?>

You can also output (save the contents of the image in a file) and store it under a thumbnail folder with the PDF name as the file name. like ( sample.jpg )

As for a solution based on laravel, I don't think laravel has any package that can do the same

Community
  • 1
  • 1
Magesh Kumaar
  • 511
  • 2
  • 11
1

Though the question was posted quite a long ago but I'm answering because it might helps others. There is a package for generating image from pdf. Pdf to Image. You should have Imagick and Ghostscript installed