On May 28, 2005, at 1:00 AM, Rich Morin wrote:

I would like a way (easy, if possible :-) to obtain a "bounding
box" for a PDF document.

#!/usr/bin/perl

use warnings;
use strict;

use CamelBones qw(:All);

my $data = NSData->dataWithContentsOfFile('resume.pdf');
my $rep = NSPDFImageRep->imageRepWithData($data);

my $bounds = $rep->bounds();

my $x = $bounds->getX()/72;
my $y = $bounds->getY()/72;
my $width = $bounds->getWidth()/72;
my $height = $bounds->getHeight()/72;

print "X: $x, Y: $y, Width: $width in, Height $height in\n";
__END__

The location and size of the PDF's "root page" rectangle are returned in points, and converted here to inches for display.

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

Reply via email to