Get the layout mode (landscape or portrait) of a pdf from php/linux
cups, ghostscript, linux, pdf, php
Solution
The solution I'm using is to use ghostscript to print the first page to an image, then getting the image dimensions
$cmd = 'gs -dSAFER -dBATCH -dNOPAUSE -dFirstPage=1 -dLastPage=1 -sDEVICE=png16m -r400 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="'.$complete_file_path.'/p%d.png" "'.$complete_file_path.'/'.$this->pdffilename.'"';
$result = $this->proc( $cmd );
list($width, $height, $type, $attr) = getimagesize($complete_file_path.'/'.$pngfilename);
Problem
Given a PDF, how can one get the layout mode of a PDF (or relative width/height) using a PHP lib or linux command line tool? Using http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf which can set this variable on new PDFs, but for existing pdfs from adobe. Thought of converting pdfs to ps, or using gs in some other way - like converting it to an image first, and getting the width and height of that. Is this the best way?