Get layout mode (landscape or portrait) pdf from php / linux

Given PDF, how can I get the PDF layout mode (or relative width / height) using the 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 in new PDF files, but for existing pdf files from adobe.

The idea of ​​converting PDF files to ps or using gs in some other way - for example, first convert it to an image and get the width and height. Is this the best way?

+3
source share
3 answers

, , - ghostscript ,

$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);
+3

, . PDF , - .

( {Trim, Media, Crop, Bleed}) - pdfinfo.exe( XPDF http://www.foolabs.com/xpdf/download.html). "-box" "-f 3", 3 "-l 8", . 8.

:

C:\downloads>pdfinfo -box -f 1 -l 3 _IXUS_850IS_ADVCUG_EN.pdf
Creator:        FrameMaker 6.0
Producer:       Acrobat Distiller 5.0.5 (Windows)
CreationDate:   08/17/06 16:43:06
ModDate:        08/22/06 12:20:24
Tagged:         no
Pages:          146
Encrypted:      no
Page    1 size: 419.535 x 297.644 pts
Page    2 size: 297.646 x 419.524 pts
Page    3 size: 297.646 x 419.524 pts
Page    1 MediaBox:     0.00     0.00   595.00   842.00
Page    1 CropBox:     87.25   430.36   506.79   728.00
Page    1 BleedBox:    87.25   430.36   506.79   728.00
Page    1 TrimBox:     87.25   430.36   506.79   728.00
Page    1 ArtBox:      87.25   430.36   506.79   728.00
Page    2 MediaBox:     0.00     0.00   595.00   842.00
Page    2 CropBox:    148.17   210.76   445.81   630.28
Page    2 BleedBox:   148.17   210.76   445.81   630.28
Page    2 TrimBox:    148.17   210.76   445.81   630.28
Page    2 ArtBox:     148.17   210.76   445.81   630.28
Page    3 MediaBox:     0.00     0.00   595.00   842.00
Page    3 CropBox:    148.17   210.76   445.81   630.28
Page    3 BleedBox:   148.17   210.76   445.81   630.28
Page    3 TrimBox:    148.17   210.76   445.81   630.28
Page    3 ArtBox:     148.17   210.76   445.81   630.28
File size:      6888764 bytes
Optimized:      yes
PDF version:    1.4
+1

Big gun, but no other suggestions. I used the iText Java library to process pdf files.

Note that, as far as I know, there is no such thing as PDF layout mode or size. PDF is a set of pages, each of which has a media box that determines the size of the printed page. However, this property can be inherited by a page from previous pages, if not defined. See PDF Help for more information .

0
source

Source: https://habr.com/ru/post/1718396/


All Articles