Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PHP Get height and width in Pdf file proprieties
- <?php
- $output = shell_exec("pdfinfo ".$pdflivrelink);
- $data = explode("n", $output); //puts it into an array
- for($c=0; $c < count($data); $c++) {
- if(stristr($data[$c],"Pages") == true) {
- $pagesnumber = trim(substr($data[$c],6));
- }
- if(stristr($data[$c],"Page size") == true) {
- $pagesize_H = height_pdf(trim(substr($data[$c],9)));
- }
- if(stristr($data[$c],"Page size") == true) {
- $pagesize_L = width_pdf(trim(substr($data[$c],9)));
- }
- }
- function height_pdf($size){
- $hauteur = round(substr($size,7,7)/2.83);
- return $hauteur;
- }
- function width_pdf($size){
- $largeur = round(substr($size,17,7)/2.83);
- return $largeur;
- } ?>
- $output = shell_exec("pdfinfo ".$pdflivrelink);
- $data = explode("n", $output); //puts it into an array
- for($c=0; $c < count($data); $c++) {
- if(stristr($data[$c],"Pages") == true) {
- $pagesnumber = trim(substr($data[$c],6));
- }
- if(stristr($data[$c],"Page size") == true) {
- echo $data[$c];
- preg_match('/Page size: ([0-9]*.?[0-9]?) x ([0-9]*.?[0-9]?)/', $data[$c], $matchess);
- $width = round($matchess[1]/2.83);
- $height = round($matchess[2]/2.83);
- }
- }
- echo "width = $width<br>height = $height";
- <?php
- $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';
- preg_match('/Page size: ([0-9]*.?[0-9]?) x ([0-9]*.?[0-9]?)/', $str, $matches);
- $width = round($matches[1]/2.83);
- $height = round($matches[2]/2.83);
- echo "width = $width<br>height = $height";
- ?>
- <?php
- $output = shell_exec("pdfinfo ".$pdflivrelink);
- // 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";
- ?>
- // Debugging:
- $output = shell_exec("pdfinfo ".$pdflivrelink);
- var_dump($output);
- // Dimension:
- preg_match('~ Page size: ([0-9.]+) x ([0-9.]+) pts ~', $output, $matches);
- var_dump($matches);
- // No of pages:
- preg_match('~ Pages ([0-9]+) ~', $output, $matches);
- var_dump($matches);
- function size_pdf($size){
- $result = array();
- $tmp = exlode('x', $size);
- $result['height'] = round(trim($tmp[0])/2.83);
- $result['width'] = round(trim($tmp[1])/2.83);
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement