在 PHP (LAMP) 中创建文档(PDF、DOC、XLS 等)的缩略图预览

2023-07-16php开发问题
0

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

问题描述

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

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

推荐答案

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

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)

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

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 等)的缩略图预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17