如何在 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]
表示 page 1
.