Skip to content

Instantly share code, notes, and snippets.

@atr000
Created May 23, 2010 11:52
Show Gist options
  • Save atr000/410870 to your computer and use it in GitHub Desktop.
Save atr000/410870 to your computer and use it in GitHub Desktop.
pdf page counter using quartz in objc
/* from scriptbuilders. cheap way to utilize quartz on osx for pdf pagecount */
#import <Foundation/Foundation.h>
#import <Quartz/Quartz.h>
int main (int argc, const char * argv[]) {
if (argc != 2){
printf("Usage: PDFPageCounter path\n");
return 1;
}
int returnValue = 0;
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *filePath = [[[NSProcessInfo processInfo] arguments] objectAtIndex:1];
NSURL *docURL = [[NSURL alloc] initFileURLWithPath:filePath];
PDFDocument *doc = [[PDFDocument alloc] initWithURL:docURL];
if (doc) {
printf("%i\n", [doc pageCount]);
[doc release];
}
else {
printf("no valid PDF document\n");
returnValue = 2;
}
[docURL release];
[pool drain];
return returnValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment