How to get page orientation on a PDF page?

The getPageDimensions (CAM :: PDF) function returns the same values ​​for both portrait and landscape pages. How to determine the orientation of a PDF page? I am using CAM :: PDF Perl library and would like to know how to do this using this library. But any other ways to identify this are also welcome (preferably using Perl lib).

Thanks.

+3
source share
1 answer

I am the author of CAM :: PDF.

Well, there are two parts. One of them is page sizes, as you noted. This works as expected: I used Apple Preview.app to rotate the PDF file and ran these two lines:

perl -MCAM::PDF -le'print "@{[CAM::PDF->new(shift)->getPageDimensions(1)]}"' orig.pdf 0 0 612 792 perl -MCAM::PDF -le'print "@{[CAM::PDF->new(shift)->getPageDimensions(1)]}"' rotated.pdf 0 0 792 612 

But also the attribute of the `/ Rotate 'page. An argument is the number of degrees (the default is 0, but 90 or 270 are not uncommon). Like page sizes, this is a property of the inherited property, so you need to go to the parent pages. Here's a quick and dirty command line tool to output the rotation value:

 use CAM::PDF; my $filename = shift || die; my $pagenum = shift || die; my $pdf = CAM::PDF->new($filename) || die; my $pagedict = $pdf->getPage($pagenum); my $rotate = 0; while ($pagedict) { $rotate = $pdf->getValue($pagedict->{Rotate}); if (defined $rotate) { last; } my $parent = $pagedict->{Parent}; $pagedict = $parent && $pdf->getValue($parent); } print "/Rotate $rotate\n"; 
+3
source

All Articles