我正在努力实现将PDF上传添加到我继承的现有图片上传功能的功能。我注意到我无法在PDF上使用getimagesize。有没有办法使用PHP确定PDF的尺寸? - 或者 - 在上传PDF时对硬件进行硬编码是否会更好。
答案 0 :(得分: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/