Solved: Creating Smaller PDFs.
Solved: Creating Smaller PDFs.
- Subject: Solved: Creating Smaller PDFs.
- From: Jerry LeVan <email@hidden>
- Date: Thu, 13 Dec 2007 22:13:12 -0500
This does not seem to be well documented but Antonio Nunes put me on
the right track.
The problem: I have a Graphic Novel in the form of a list of filenames
of
jpgs. I want to create a PDF image of the Novel from within my
App. The "obvious way" shown below has a problem with the resulting
size of the PDF. A fourteen page novel ( 8MB) can produce a 54MB
PDF.
The solution:
I used the Color Sync Utility to create a jpg compression filter see
page 21 of http://images.apple.com/pro/pdf/Color_Mgmt_inTiger.pdf for
details of how to do this. I named my filter "Reduced File Size JPG".
I selected a 50% value on the scale.
I could not find any way to create this filter programatically.
As Antonio pointed out the key idea is found in the PDFDocument.h
file.
// Methods to record the current state of the PDFDocument as
data or a file.
Passing a QuartzFilter object in the
// options dictionary with the key @"QuartzFilter" will allow you to
have
the filter applied when saving the PDF.
- (BOOL) writeToFile: (NSString *) path withOptions:
(NSDictionary *) options;
*****************************
The following code with the compression added reduced my 54MB file to
6.9MB.
Here is a fragment of the code:
// loop to build pdf
int cnt = [ fileNameList count];
for (i=0; i< cnt ; i++) {
nextImage = [[NSImage alloc] initWithContentsOfFile:(NSString*)
[fileNameList objectAtIndex:i]];
nextPDFPage = [[PDFPage alloc] initWithImage:nextImage];
[myBook insertPage: nextPDFPage atIndex: i];
[nextImage release];
[nextPDFPage release];
}
// Compression Code follows...
NSArray *filters = [QuartzFilterManager filtersInDomains:[NSArray
arrayWithObject:@"QuartzFilterPDFWorkflowDomain"]];
int search = [self findSpecialFilter: filters byName:@"Reduced File
Size JPG"];
if ( search != -1 ) {
QuartzFilter *f = [filters objectAtIndex:search];
NSDictionary * optionsDictWithQuartzFilter = [NSDictionary
dictionaryWithObject: f forKey:@"QuartzFilter"];
[myBook writeToFile:@"/Users/jerry/Desktop/Book.pdf"
withOptions:optionsDictWithQuartzFilter ];
}
else {
[myBook writeToFile:@"/Users/jerry/Desktop/Book.pdf"];
}
[myBook release];
return;
}
-(int) findSpecialFilter: (NSArray*) filterList byName: theName
{
int cnt = [filterList count];
int i;
for( i=0 ; i < cnt ; i++) {
if ([[[filterList objectAtIndex: i] localizedName]
isEqualToString: theName] ) return i;
}
return -1 ;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden