Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2012
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. PHP Get height and width in Pdf file proprieties
  2. <?php
  3. $output = shell_exec("pdfinfo ".$pdflivrelink);
  4. $data = explode("n", $output); //puts it into an array
  5. for($c=0; $c < count($data); $c++) {
  6. if(stristr($data[$c],"Pages") == true) {
  7. $pagesnumber = trim(substr($data[$c],6));
  8. }
  9. if(stristr($data[$c],"Page size") == true) {
  10. $pagesize_H = height_pdf(trim(substr($data[$c],9)));
  11. }
  12. if(stristr($data[$c],"Page size") == true) {
  13. $pagesize_L = width_pdf(trim(substr($data[$c],9)));
  14. }
  15.  
  16. }
  17. function height_pdf($size){
  18. $hauteur = round(substr($size,7,7)/2.83);
  19. return $hauteur;
  20. }
  21. function width_pdf($size){
  22. $largeur = round(substr($size,17,7)/2.83);
  23. return $largeur;
  24. } ?>
  25.  
  26. $output = shell_exec("pdfinfo ".$pdflivrelink);
  27. $data = explode("n", $output); //puts it into an array
  28. for($c=0; $c < count($data); $c++) {
  29. if(stristr($data[$c],"Pages") == true) {
  30. $pagesnumber = trim(substr($data[$c],6));
  31.  
  32. }
  33. if(stristr($data[$c],"Page size") == true) {
  34. echo $data[$c];
  35. preg_match('/Page size: ([0-9]*.?[0-9]?) x ([0-9]*.?[0-9]?)/', $data[$c], $matchess);
  36. $width = round($matchess[1]/2.83);
  37. $height = round($matchess[2]/2.83);
  38.  
  39. }
  40. }
  41. echo "width = $width<br>height = $height";
  42.  
  43. <?php
  44. $str = 'Creator: pdftk 1.41 - www.pdftk.com Producer: iText 2.1.5 (by lowagie.com) CreationDate: Mon Feb 27 13:18:23 2012 ModDate: Mon Feb 27 16:26:12 2012 Tagged: no Pages: 36 Encrypted: no Page size: 425.2 x 538.582 pts File size: 5097597 bytes Optimized: yes PDF version: 1.6';
  45.  
  46. preg_match('/Page size: ([0-9]*.?[0-9]?) x ([0-9]*.?[0-9]?)/', $str, $matches);
  47. $width = round($matches[1]/2.83);
  48. $height = round($matches[2]/2.83);
  49.  
  50. echo "width = $width<br>height = $height";
  51. ?>
  52.  
  53. <?php
  54.  
  55. $output = shell_exec("pdfinfo ".$pdflivrelink);
  56.  
  57. // find page count
  58. preg_match('/Pages:s+([0-9]+)/', $output, $pagecountmatches);
  59. $pagecount = $pagecountmatches[1];
  60.  
  61. // find page sizes
  62. preg_match('/Page size:s+([0-9]{0,5}.?[0-9]{0,3}) x ([0-9]{0,5}.?[0-9]{0,3})/', $output, $pagesizematches);
  63. $width = round($pagesizematches[1]/2.83);
  64. $height = round($pagesizematches[2]/2.83);
  65.  
  66. echo "pagecount = $pagecount <br>width = $width<br>height = $height";
  67.  
  68. ?>
  69.  
  70. // Debugging:
  71. $output = shell_exec("pdfinfo ".$pdflivrelink);
  72. var_dump($output);
  73.  
  74. // Dimension:
  75. preg_match('~ Page size: ([0-9.]+) x ([0-9.]+) pts ~', $output, $matches);
  76. var_dump($matches);
  77.  
  78.  
  79. // No of pages:
  80. preg_match('~ Pages ([0-9]+) ~', $output, $matches);
  81. var_dump($matches);
  82.  
  83. function size_pdf($size){
  84. $result = array();
  85. $tmp = exlode('x', $size);
  86. $result['height'] = round(trim($tmp[0])/2.83);
  87. $result['width'] = round(trim($tmp[1])/2.83);
  88.  
  89. return $result;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement