Reading PDF metadata in PHP

后端 未结 6 1530
你的背包
你的背包 2020-12-08 17:55

I\'m trying to read metadata attached to arbitrary PDFs: title, author, subject, and keywords.

Is there a PHP library, preferably open-source, that can read PDF meta

6条回答
  •  感动是毒
    2020-12-08 18:22

    You may use PDFtk to extract the page count:

    // Windows
    $bin = realpath('C:\\pdftk\\bin\\pdftk.exe');
    $cmd = "cmd /c {$bin} {$path} dump_data | grep NumberOfPages | sed 's/[^0-9]*//'";
    
    // Unix
    $cmd = "pdftk {$path} dump_data | grep NumberOfPages | sed 's/[^0-9]*
    

    If ImageMagick is available you may also use:

    $cmd = "identify -format %n {$path}";
    

    Execute in PHP via shell_exec():

    $res = shell_exec($cmd);
    

提交回复
热议问题