在PHP(LAMP)中创建文档的缩略图预览(PDF,DOC,XLS等) [英] Create a thumbnail preview of documents (PDF, DOC, XLS, etc.) in PHP (LAMP)

查看:136
本文介绍了在PHP(LAMP)中创建文档的缩略图预览(PDF,DOC,XLS等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户将某些文件上传到我的网站时(例如.doc,.xls,.pdf等),我希望能够生成(文档第一页的)预览缩略图。我正在使用LAMP堆栈中的PHP,但会对任何可以完成这项工作的库或命令行工具感到满意(Linux是高度优先的)。

解决方案

将某些文档格式转换为图像并不容易。单独的PHP不能做到这一点。
执行此操作的正确方法是首先在您的服务器上安装程序,以便以该格式打开文档。
例如,对于.doc文档,您可以使用OpenOffice
,它也可以打开大多数其他文档格式
然后您需要设置开放式办公室以无头模式工作,发送输出到虚拟显示器(XVFB是你在Linux上需要的)


然后你的php脚本将调用OpenOffice,将路径传递给上传的文档。 OpenOffice实际上会打开该文档。然后你需要从屏幕缓冲区创建一个图像。您可以为ImageMagick使用



然后,一旦您捕获了屏幕,就可以将其调整为缩略图。



看看这个链接的更多细节

http://www.mysql-apache-php.com/website_screenshot.htm


When users upload certain files to my site (such as .doc, .xls, .pdf, etc) I'd like to be able to generate a preview thumbnail (of the first page of the document). I'm working with PHP in a LAMP stack but would be happy with any library or command-line tool that can do the job (Linux highly preferred).

解决方案

It's not easy to convert certain document formats to image. php alone cannot do this. The 'proper' way to do this is to first of all have the program installed on your server that can open the document in that format. For example, for .doc documents you can use OpenOffice it also can open most other document formats You then need to setup your open office to work in 'headless' mode, sending the output to virtual display (XVFB is what you going to need on Linux)

You php script will then call OpenOffice, passing the path to uploaded doc. OpenOffice will actually open that doc. Then you need to create an image from the screen buffer. You can use ImageMagick for that

Then once you have the capture of your screen you can resize it to a thumbnail.

Look at this link for more details

http://www.mysql-apache-php.com/website_screenshot.htm

这篇关于在PHP(LAMP)中创建文档的缩略图预览(PDF,DOC,XLS等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆