I would like a way (easy, if possible :-) to obtain a "bounding
box" for a PDF document. That is, the smallest rectangle that
does not clip off any recognizable glyphs. (I will probably
add a small margin for error, just to be "safe").
FWIW, I hope to use this information to adjust (e.g., scale and
translate) the document to have desired indentation and margins.
I have done the adjustment before, but I want to get "out of the
loop" of analyzing each document.
The "Hard Way" to accomplish this would be to obtain and analyze
a rasterized version of the document (as might be sent to a dot
matrix printer). An "Easy Way" would be to find a way to get
OSX (or whatever) to tell me about the document.
Clues? Suggestions?
-r

Signature
email: rdm@cfcl.com; phone: +1 650-873-7841
http://www.cfcl.com - Canta Forda Computer Laboratory
http://www.cfcl.com/Meta - The FreeBSD Browser, Meta Project, etc.
Sherm Pendley - 28 May 2005 08:31 GMT
> 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