在PHP中将PDF文档转换为预览图像,而无需安装Ghostscript

时间:2022-10-30 12:01:23

This has been asked before but the answer is always to use ghost script. This isn't available on hosts using cpanel. Is it possible to do without ghostscript extension installed?

这已被问过,但答案总是使用ghost脚本。这在使用cpanel的主机上不可用。是否可以不安装ghostscript扩展?

Thanks

谢谢

4 个解决方案

#1


1  

Just a quick suggestion for those considering using an external service to achieve this: now, some APIs allow to upload documents and retrieve their related info, thumbnail, etc.

对于那些考虑使用外部服务来实现这一点的人来说,只是一个快速建议:现在,一些API允许上传文档并检索相关信息,缩略图等。

For instance see Cloudinary (which offers a free plan) : https://cloudinary.com/blog/uploading_converting_and_generating_thumbnails_for_pdf_documents

例如,请参阅Cloudinary(提供免费计划):https://cloudinary.com/blog/uploading_converting_and_generating_thumbnails_for_pdf_documents

#2


0  

How do I convert a PDF document to a preview image in PHP? << This link had a solution posted by someone using GD. I've not tested it, but it may help someone...

如何在PHP中将PDF文档转换为预览图像? < <此链接有一个使用gd的人发布的解决方案。我没有测试过,但它可能对某人有所帮助......< p>

#3


0  

You could compile a single binary of Imagemagick and deploy that to the webserver, like this guy. His issue sounds much like yours

您可以编译Imagemagick的单个二进制文件并将其部署到Web服务器,就像这个人一样。他的问题听起来很像你的问题

I need to deploy ImageMagick's "convert" utility on a a shared host, where I don't have access to /usr/lib, env or anything else except the webspace. I can however drop a binary into the webspace, chmod it to 755 and run it (from the Apache context).

我需要在共享主机上部署ImageMagick的“转换”实用程序,在那里我无法访问/ usr / lib,env或除了webspace之外的任何其他内容。然而,我可以将二进制文件放入网站空间,将其修改为755并运行它(从Apache上下文)。

Building the standalone binary means it can include ghostscript as part of the binary. If you can't build on the target host, use a VM with the same OS, build the binary, then upload that to your webroot and call it w/ exec et al

构建独立二进制文件意味着它可以包含ghostscript作为二进制文件的一部分。如果您无法在目标主机上构建,请使用具有相同操作系统的VM,构建二进制文件,然后将其上载到您的webroot并将其调用w / exec et al

#4


0  

You need ImageMagick and GhostScript

你需要ImageMagick和GhostScript

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

The [0] means page 1. i found it somewhere you may help :)

[0]表示第1页。我发现它可能会帮助你:)

#1


1  

Just a quick suggestion for those considering using an external service to achieve this: now, some APIs allow to upload documents and retrieve their related info, thumbnail, etc.

对于那些考虑使用外部服务来实现这一点的人来说,只是一个快速建议:现在,一些API允许上传文档并检索相关信息,缩略图等。

For instance see Cloudinary (which offers a free plan) : https://cloudinary.com/blog/uploading_converting_and_generating_thumbnails_for_pdf_documents

例如,请参阅Cloudinary(提供免费计划):https://cloudinary.com/blog/uploading_converting_and_generating_thumbnails_for_pdf_documents

#2


0  

How do I convert a PDF document to a preview image in PHP? << This link had a solution posted by someone using GD. I've not tested it, but it may help someone...

如何在PHP中将PDF文档转换为预览图像? < <此链接有一个使用gd的人发布的解决方案。我没有测试过,但它可能对某人有所帮助......< p>

#3


0  

You could compile a single binary of Imagemagick and deploy that to the webserver, like this guy. His issue sounds much like yours

您可以编译Imagemagick的单个二进制文件并将其部署到Web服务器,就像这个人一样。他的问题听起来很像你的问题

I need to deploy ImageMagick's "convert" utility on a a shared host, where I don't have access to /usr/lib, env or anything else except the webspace. I can however drop a binary into the webspace, chmod it to 755 and run it (from the Apache context).

我需要在共享主机上部署ImageMagick的“转换”实用程序,在那里我无法访问/ usr / lib,env或除了webspace之外的任何其他内容。然而,我可以将二进制文件放入网站空间,将其修改为755并运行它(从Apache上下文)。

Building the standalone binary means it can include ghostscript as part of the binary. If you can't build on the target host, use a VM with the same OS, build the binary, then upload that to your webroot and call it w/ exec et al

构建独立二进制文件意味着它可以包含ghostscript作为二进制文件的一部分。如果您无法在目标主机上构建,请使用具有相同操作系统的VM,构建二进制文件,然后将其上载到您的webroot并将其调用w / exec et al

#4


0  

You need ImageMagick and GhostScript

你需要ImageMagick和GhostScript

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

The [0] means page 1. i found it somewhere you may help :)

[0]表示第1页。我发现它可能会帮助你:)