From 0420758286941759b77bd4fb0c8433e2c80442b7 Mon Sep 17 00:00:00 2001 From: Rob Mayoff Date: Sat, 30 Jul 2016 12:52:48 -0500 Subject: [PATCH] also extract PDFs --- cartool/main.m | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/cartool/main.m b/cartool/main.m index 9237bf2..7d76d43 100644 --- a/cartool/main.m +++ b/cartool/main.m @@ -66,10 +66,11 @@ -(id)allImageNames; -(CUINamedImage *)imageWithName:(NSString *)n scaleFactor:(CGFloat)s; -(CUINamedImage *)imageWithName:(NSString *)n scaleFactor:(CGFloat)s deviceIdiom:(int)idiom; -(NSArray *)imagesWithName:(NSString *)n; +-(CGPDFDocumentRef)pdfDocumentWithName:(NSString *)n; @end - +CGDataProviderRef CGPDFDocumentGetDataProvider(CGPDFDocumentRef); void CGImageWriteToFile(CGImageRef image, NSString *path) { @@ -149,6 +150,31 @@ void exportCarFileAtPath(NSString * carPath, NSString *outputDirectoryPath) for (NSString *key in [storage allRenditionNames]) { printf("%s\n", [key UTF8String]); + + CGPDFDocumentRef pdf = [catalog pdfDocumentWithName:key]; + if (pdf != NULL) + { + CGDataProviderRef provider = CGPDFDocumentGetDataProvider(pdf); + NSData *data = provider ? CFBridgingRelease(CGDataProviderCopyData(provider)) : nil; + if (data == nil) + { + printf("\tnull pdf?\n"); + } + else + { + if( outputDirectoryPath ) + { + NSString *filename = [key stringByAppendingPathExtension:@"pdf"]; + printf("\t%s\n", [filename UTF8String]); + NSError *error; + NSString *path = [outputDirectoryPath stringByAppendingPathComponent:filename]; + if ( ![data writeToFile:path options:NSDataWritingWithoutOverwriting error:&error] ) + { + NSLog(@"Failed to write PDF to %@: %@", path, error); + } + } + } + } NSArray *images = [catalog imagesWithName:key]; for( CUINamedImage *image in images )