views:

35

answers:

0

Hello,

I have a program that composites the pages of a PDF into a single image with each page stacked on top of each the previous one. The program works fine, but the font rendering quality is much lower when run from anything but a Snow Leopard system. In Leopard, the text looks jagged and not antialiased properly. Does anyone know a fix for this? Here is my code.

NSString* path = [[oPanel filenames] objectAtIndex: 0];
NSPDFImageRep *pdf = [NSPDFImageRep imageRepWithContentsOfFile: path];

int pageHeight = 765;
int pageWidth = 990;
int pages = [pdf pageCount];
int height = pageHeight * pages;

NSImage *compositeImage = [[NSImage alloc] initWithSize:NSMakeSize(pageWidth, height)];
[compositeImage lockFocus];

for (int i = 0; i < pages; i++) {
    [pdf setCurrentPage: i];

    NSImage *page = [[NSImage alloc] init];
    [page addRepresentation:pdf];

    NSSize size = [pdf bounds].size;
    int width = round(pageHeight * size.width / size.height);

    [page drawInRect: NSMakeRect(0, height - pageHeight * (i + 1), width, pageHeight) 
            fromRect: NSZeroRect 
           operation: NSCompositeSourceOver 
            fraction: 1.0];

    [page release];
}

[compositeImage unlockFocus];

NSBitmapImageRep *rep = [NSBitmapImageRep imageRepWithData: [compositeImage TIFFRepresentation]];
NSData *imageData = [rep representationUsingType: NSJPEGFileType properties: nil];
[imageData writeToFile:@"/Users/devongovett/Desktop/out.jpg" atomically: YES];