Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

also extract PDFs #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion cartool/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 )
Expand Down