如何在PHP中将PDF文档转换为预览图像?

如何在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.

您需要 ImageMagick GhostScript

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

[0] 表示第1页