Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / May 2005



Tip: Looking for answers? Try searching our database.

getting a "bounding box" for a PDF document?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rich Morin - 28 May 2005 06:00 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.