Home

Tuesday, September 16, 2014

How to get PDF boxes information using PHP

If you want to extract Total no of pages,Creator,Creation Date,Producer,Tagged,Page size,MediaBox,CropBox,BleedBox,TrimBox,ArtBox,File size,PDF version etc then you can used below code.

---------------------------------------------------------------------------------------------------------------------
$file_name = "files/client_bussinesscard_front.pdf";
echo "<b>All Details : </b>";
$command_pagesize8 = "pdfinfo -box  $file_name";
shell_exec($command_pagesize8); //run the command
echo "<br><br><hr>";

echo "<b>Total Pages : </b>";
$command_pagesize1 = "pdfinfo -box  $file_name | grep Pages";
shell_exec($command_pagesize1); //run the command
echo "<br><br><hr>";

echo "<b>Page size : </b>";
$command_pagesize2 = "pdfinfo -box  $file_name | grep 'Page size'";
shell_exec($command_pagesize2); //run the command
echo "<br><br><hr>";

$command_pagesize3 = "pdfinfo -box  $file_name | grep 'MediaBox'";
mm($command_pagesize3,"<b>MediaBox Details (wight x height):</b><br>");

$command_pagesize4 = "pdfinfo -box  $file_name | grep 'CropBox'";
mm($command_pagesize4,"<b>CropBox Details (wight x height):</b><br>");

$command_pagesize5 = "pdfinfo -box  $file_name | grep 'BleedBox'";
mm($command_pagesize5,"<b>BleedBox Details (wight x height):</b><br>");

$command_pagesize6 = "pdfinfo -box  $file_name | grep 'TrimBox'";
mm($command_pagesize6,"<b>TrimBox Details (wight x height):</b><br>");

$command_pagesize7 = "pdfinfo -box  $file_name | grep 'ArtBox'";
mm($command_pagesize7,"<b>ArtBox Details (wight x height):</b><br>");

function mm($command,$title)
{
    echo $title;   
    $array = explode(" ",shell_exec($command));   
    foreach($array as $val)
    {
      if($val!="")
      {
          $final_array[].=$val;
      }
    }   
    ?>
    <table width="50%" border="1">
        <tr><th>Points</th><th>MM</th></tr>
        <tr>
            <td align="center"><?php echo $final_array[3] . " x " .$final_array[4]; ?></td>
            <td align="center"><?php echo round(($final_array[3]*0.35277777778),2) . " x " .round(($final_array[4]*0.35277777778),2);?><br>
            <?php echo round(($final_array[3]*0.35277777778)) . " x " .round(($final_array[4]*0.35277777778));?></td>
           </tr>
    </table>
    <?php   
}

No comments:

Post a Comment

rathoddhirendra.blogspot.com-Google pagerank and Worth