库以将 PDF 转换为图像


library to convert pdf to image

嗨,朋友们,我是Codeigniter的新手。在我的新项目中,我有一个上传pdf文件的任务,我必须将其转换为图像。任何人都可以建议我的解决方案是有任何库函数可以转换它,如果可能的话,还可以给我一些工作代码。提前致谢

您可以使用 ImageMagick 和 GhostScript 将 PDF 文件转换为图像。在这里查看这个 PHP 库。

此类可用于使用 Ghostscript 将 PDF 文档转换为图像。它采用上传的PDF文件,并使用Ghostscript程序将其转换为JPEG图像。

注意:转换后的图像存储在根据相应PDF文档页面编号的文件中。

你可以使用我写的PDFlib php包装器,像下面这样使用它

$pdflib = new ImalH'PDFLib'PDFLib();
$pdflib->setPdfPath("pdf file path");
$pdflib->setOutputPath("output folder path");
$pdflib->setImageFormat('ImalH'PDFLib'PDFLib::$IMAGE_FORMAT_PNG);
$pdflib->setDPI(300);
$pdflib->setPageRange(1,$pdflib->getNumberOfPages());
$pdflib->convert();

通过一个简单的谷歌,我从其他地方得到了这个答案。

图像库支持ImageMagick(如果已在服务器上安装):https://ellislab.com/codeigniter/user-guide/libraries/image_lib.html

$config = array(
    'image_library' => 'imagemagick',
    'library_path' => 'imagemagick_file_path_goes_here',
    'source_image' => $pdf_path,
    'new_image' => $img_path,
    'maintain_ratio' => true,
    'width' => 365,
    'quality' => '100%',
   );
   $this->image_lib->initialize( $config );
   if ( $this->image_lib->resize( ) ) {
    $this->image_lib->clear( );
   }