Laravel 5.1 中的 PDF 图像缩略图预览?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32630450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:21:39  来源:igfitidea点击:

PDF Image thumbnail preview in laravel 5.1?

phplaravelpdfpreviewlaravel-5.1

提问by gsk

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 storagefolder,which is not accessible via http.

我将文件存储在storage文件夹中,无法通过http.

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

那么如何为文档,尤其是图像和 PDF 提供缩略图预览。

Is there any package availabe in laravel 5.1?

laravel 5.1 中是否有可用的软件包?

回答by Magesh Kumaar

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

PDF 文件的预览图像通常是 PDF 文件的第一页

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

您可以使用ImageMagick获取 PDF 文件的第一页。

<?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 )

您还可以输出(将图像内容保存在文件中)并将其存储在以 PDF 名称作为文件名的缩略图文件夹下。喜欢(样本.jpg)

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

至于基于laravel的解决方案,我认为laravel没有任何可以做到这一点的包

回答by Zaman-A-Piri Pasa

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 Imagickand Ghostscriptinstalled

虽然这个问题是很久以前发布的,但我正在回答,因为它可能会帮助其他人。有一个用于从 pdf 生成图像的包。Pdf 到图像。你应该有ImagickGhostscript的安装