Solved: Creating Smaller PDFs.

  • 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 ;
    }
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today