【问题标题】:PHP getimagesize of PDF -> BlobPDF的PHP getimagesize - > Blob
【发布时间】:2012-09-26 18:11:03
【问题描述】:

我正在尝试实现将 PDF 上传添加到我继承的现有图像上传功能的能力。我注意到我无法在 PDF 上使用 getimagesize。有没有办法使用 PHP 确定 PDF 的尺寸? - 或者 - 上传 PDF 时对尺寸进行硬编码会更好吗?

【问题讨论】:

  • 是否将 PDF 转换为 JPEG,然后再将图像的大小排除在外? stackoverflow.com/questions/9227014/…
  • @EricLeschinski 如果可能的话,我想保留它们的 PDF,但我不反对使用插件来查找大小。

标签: php oracle pdf getimagesize


【解决方案1】:

选项 1

pdfinfo.exe(XPDF 工具的一部分)具有指定要获取尺寸的页面或所有页面的参数。

<?php
    $output = shell_exec("pdfinfo ".$your_pdf_file_or_url);

    // find page count
    preg_match('/Pages:\s+([0-9]+)/', $output, $pagecountmatches);
    $pagecount = $pagecountmatches[1];

    // find page sizes
    preg_match('/Page size:\s+([0-9]{0,5}\.?[0-9]{0,3}) x ([0-9]{0,5}\.?[0-9]{0,3})/', 
         $output, $pagesizematches);
    $width = round($pagesizematches[1]/2.83);
    $height = round($pagesizematches[2]/2.83);

    echo "pagecount = $pagecount <br>width = $width<br>height = $height";

?>

http://www.foolabs.com/xpdf/download.html

Get the layout mode (landscape or portrait) of a pdf from php/linux

PHP Get height and width in Pdf file proprieties

选项 2

如果您在安装了 Image Magick 的 linux 服务器上:

$command = escapeshellcmd('identify -format "%wx%h" ' . $path_to_pdf) . '[0]';
$geometry = `$command`;
list($width, $height) = split("x", $geometry);

然后您可以通过 $width 和 $height 访问尺寸。

http://forums.phpfreaks.com/topic/134081-find-out-width-and-height-of-a-given-pdf-file/

【讨论】:

  • 这就是我的落脚点,我只是希望有一种更“内置”的方式来做到这一点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-25
  • 2011-06-05
  • 1970-01-01
相关资源
最近更新 更多