Problem: PDF Kit generates hugh PDF files.

  • Hi,

    This post evidently did not make it to the list, at least
    it has not appeared in the Digest that I receive...

    I am having a problem with the PDF Kit, the generated pdfs are
    up to seven ( or more ) times the size of the same pdfs generated
    with the same data as Acrobat and other applications

    I have a "book" made out of 14 jpeg images totaling about 8384KB.

    Here are some results for the conversion to pdf
    Jomix    8.2 MB
    Acrobat  8.3 MB
    MakePDF 54.4 MB

    How can I reduce the size of the pdf generated by the following code ?

    Thanks

    Jerry

    -(IBAction) MakePDF:(id)sender
    {
    PDFDocument* myBook;
    PDFPage * nextPDFPage;
    NSImage* nextImage;
    int i;
            NSBundle *thisBundle = [NSBundle bundleForClass:[self class]];
            NSString * emptypdf = [thisBundle pathForResource:@"Empty.pdf"
    ofType:nil] ;

    myBook = [[PDFDocument alloc] initWithData:[NSData
    dataWithContentsOfFile:emptypdf]];

    if (myBook == NULL){
           NSLog(@"Create PDF Failed");
         return;
    }

    [myBook removePageAtIndex:0];

    // 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];
    }

    [myBook writeToFile:@"/Users/jerry/Desktop/Book.pdf"];

    [myBook release];

    return;
    }
  • Not an expert on this, but im guessing the jpegs are being
    decompressed into a bitmap format here:

      nextImage = [[NSImage alloc] initWithContentsOfFile:(NSString*)
    [fileNameList objectAtIndex:i]];

    And then you are simply adding that bitmap to the pdf. Sounds like you
    need to find some way of re-compressing the image data when you add it
    to the pdf.

    Cheers
    Nik

    On 12/12/2007, at 11:46 AM, Jerry LeVan wrote:

    > Hi,
    >
    > This post evidently did not make it to the list, at least
    > it has not appeared in the Digest that I receive...
    >
    > I am having a problem with the PDF Kit, the generated pdfs are
    > up to seven ( or more ) times the size of the same pdfs generated
    > with the same data as Acrobat and other applications
    >
    >
    > I have a "book" made out of 14 jpeg images totaling about 8384KB.
    >
    > Here are some results for the conversion to pdf
    > Jomix    8.2 MB
    > Acrobat  8.3 MB
    > MakePDF 54.4 MB
    >
    > How can I reduce the size of the pdf generated by the following code ?
    >
    > Thanks
    >
    > Jerry
    >
    > -(IBAction) MakePDF:(id)sender
    > {
    > PDFDocument* myBook;
    > PDFPage * nextPDFPage;
    > NSImage* nextImage;
    > int i;
    > NSBundle *thisBundle = [NSBundle bundleForClass:[self class]];
    > NSString * emptypdf = [thisBundle pathForResource:@"Empty.pdf"
    > ofType:nil] ;
    >
    > myBook = [[PDFDocument alloc] initWithData:[NSData
    > dataWithContentsOfFile:emptypdf]];
    >
    > if (myBook == NULL){
    > NSLog(@"Create PDF Failed");
    > return;
    > }
    >
    > [myBook removePageAtIndex:0];
    >
    > // 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];
    > }
    >
    > [myBook writeToFile:@"/Users/jerry/Desktop/Book.pdf"];
    >
    > [myBook release];
    >
    > return;
    > }
  • On Dec 12, 2007, at 6:52 PM, Nik Youdale wrote:

    > Not an expert on this, but im guessing the jpegs are being
    > decompressed into a bitmap format here:
    >
    > nextImage = [[NSImage alloc] initWithContentsOfFile:(NSString*)
    > [fileNameList objectAtIndex:i]];
    >
    > And then you are simply adding that bitmap to the pdf. Sounds like
    > you need to find some way of re-compressing the image data when you
    > add it to the pdf.
    >
    > Cheers
    > Nik
    >
    > On 12/12/2007, at 11:46 AM, Jerry LeVan wrote:
    >
    >> Hi,
    >>
    >> This post evidently did not make it to the list, at least
    >> it has not appeared in the Digest that I receive...
    >>
    >> I am having a problem with the PDF Kit, the generated pdfs are
    >> up to seven ( or more ) times the size of the same pdfs generated
    >> with the same data as Acrobat and other applications
    >>
    >>
    >> I have a "book" made out of 14 jpeg images totaling about 8384KB.
    >>
    >> Here are some results for the conversion to pdf
    >> Jomix    8.2 MB
    >> Acrobat  8.3 MB
    >> MakePDF 54.4 MB
    >>
    >> How can I reduce the size of the pdf generated by the following
    >> code ?
    >>

    Exactly :)

    I need to apply the core image jpg compression filter but at this point
    in time it is not clear to me how to perform the task. I am trying to
    read the fine manual and am searching for a 'simple' Cocoa program to
    illustrate the technique.

    As a workaround I found this article http://www.hoboes.com/Mimsy/?ART=360
    It shows how to add a jpg compression filter using the ColorSync Utility
    I can then run the 54 MB pdf mentioned above through Preview. Using
    the save as option choose my filter and do the compression.

    I converted the 54MB to a 3.4MB file and it looked nearly as good
    on my iRex iLiad ( ebook reader ) as the 54 MB version and page
    changes go a lot faster.

    Anyone got any simple programs that they are willing to share :)

    Jerry
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