Skip to content
Advertisement

Get properties of a pdf file by using PHP

I have on pdf document. I want to print the details of pdf like page size by using php.

I have this code

<?php 

  $pdffile = "C:UserssureshDownloadsInvoice_52683.pdf";
  $pdfinfo = shell_exec("pdfinfo ".$pdffile); 

  // find height and width
  preg_match('/Page size:s+([0-9]{0,5}.?[0-9]{0,3}) x ([0-9]{0,5}.?[0-9]{0,3})/',      $pdfinfo,$heightandwidth); 
  echo $width = $heightandwidth[1]; 
  echo $height = $heightandwidth[2]; 

 ?> 

This is my code can any one help regarding this.

Thanks in advance

Advertisement

Answer

First check your pdfinfo‘s path, if you don’t have it: XPDF… so then change your code:

$pdffile = "C:\Users\suresh\Downloads\Invoice_52683.pdf";
$pdfinfo_path = "C:\path\to\pdfinfo.exe";
$pdfinfo = shell_exec($pdfinfo_path." ".$pdffile);

// find height and width
preg_match('/Page size:s+([0-9]{0,5}.?[0-9]{0,3}) x ([0-9]{0,5}.?[0-9]{0,3})/',$pdfinfo,$heightandwidth); 
echo $width = $heightandwidth[1]; 
echo $height = $heightandwidth[2];

If you use Linux: $pdfinfo_path = "/path/to/pdfinfo";

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement