如何获得PDF页面的页面方向

如何获得PDF页面的页面方向

本文介绍了如何获得PDF页面的页面方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

函数getPageDimensions(属于CAM :: PDF)为纵向和横向页面返回相同的值.如何确定PDF页面的方向?我正在使用CAM :: PDF Perl库,想知道如何使用此库.但是,也可以使用其他任何方法来识别这种情况(最好使用Perl库).

The function getPageDimensions (of CAM::PDF) returns same values for both portrait and landscape pages.How can I identify 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 means to identify this is also welcome (preferably using a Perl lib).

谢谢.

推荐答案

我是CAM :: PDF的作者.

I'm the author of CAM::PDF.

嗯,这有两个部分.正如您所指出的,其中之一就是页面的尺寸.可以按预期工作:我使用Apple的Preview.app旋转PDF文件并运行以下两个命令行:

Well, there's two parts to this. One is the page's dimensions, as you noted. That works as expected: I used Apple's Preview.app to rotate a PDF file and ran these two command 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

但是还有`/Rotate'页面属性.该参数是一个度数(默认为0,但90或270并不罕见).像页面尺寸一样,它是一个可继承的属性,因此您必须导航到父页面.这是一个用于输出旋转值的快捷命令行工具:

But there's also the `/Rotate' page attribute. The argument is a number of degrees (default 0, but 90 or 270 are not uncommon). Like page dimensions, it's an inheritable property so you have to navigate to 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";

这篇关于如何获得PDF页面的页面方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 17:59