如何在 PHP 中将 PDF 文档转换为预览图像? [英] How do I convert a PDF document to a preview image in PHP?

查看:27
本文介绍了如何在 PHP 中将 PDF 文档转换为预览图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 PDF 文档的一部分呈现为图像文件需要哪些库、扩展程序等?

What libraries, extensions etc. would be required to render a portion of a PDF document to an image file?

我发现的大多数 PHP PDF 库都以创建 PDF 文档为中心,但是有没有一种简单的方法可以将文档呈现为适合 Web 使用的图像格式?

Most PHP PDF libraries that I have found center around creating PDF documents, but is there a simple way to render a document to an image format suitable for web use?

我们的环境是一个 LAMP 堆栈.

Our environment is a LAMP stack.

推荐答案

您需要 ImageMagickGhostScript

<?php
$im = new imagick('file.pdf[0]');
$im->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo $im;
?>

[0] 表示 page 1.

这篇关于如何在 PHP 中将 PDF 文档转换为预览图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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