PDF Problem
PDF Problem
- Subject: PDF Problem
- From: Devon Govett <email@hidden>
- Date: Thu, 8 Jan 2009 07:40:50 -0500
Hello everyone,
I have developed an application that converts a PDF to a bitmap
image. The program creates an image in which all of the pages in the
PDF are stacked - one on top of the other. But I have a problem.
When the program is run on a PowerPC running Tiger, the quality is
much worse than when I do the same thing from an Intel based machine
running leopard. I think that maybe the Tiger api is not
antialiasing, but I tried explicitly telling it to do so with no
effect. The code is below:
NSRect viewBounds = [[pdfDoc pageAtIndex:0]
boundsForBox:kPDFDisplayBoxMediaBox];
int height = (int)(viewBounds.size.height * 1.25) * [pdfDoc
pageCount];
int pageHeight = (int)(viewBounds.size.height * 1.25);
NSRect rect = { 0,height-pageHeight, 990, pageHeight };
NSSize size = NSMakeSize(990, height);
NSImage * compositeImage;
compositeImage = [[NSImage alloc] initWithSize:size];
[compositeImage lockFocus];
[[NSGraphicsContext currentContext]
setImageInterpolation: NSImageInterpolationHigh];
[[NSGraphicsContext currentContext] setShouldAntialias:YES];
NSData* theData = [pdfDoc dataRepresentation];
NSPDFImageRep* pdfRep = [NSPDFImageRep imageRepWithData:theData];
NSImage* pdfImage;
int i;
for(i=0;i<[pdfDoc pageCount];i++){
[pdfRep setCurrentPage:i];
NSRect pageW = [[pdfDoc pageAtIndex:i]
boundsForBox:kPDFDisplayBoxMediaBox];
pdfImage = [[NSImage alloc] initWithSize: pageW.size];
NSSize fullSize = NSMakeSize(pageW.size.width*1.25, pageHeight);
[pdfImage setScalesWhenResized:YES];
[pdfImage setSize:fullSize];
[pdfImage addRepresentation:pdfRep];
NSRect r = { 0, rect.origin.y, pageW.size.width*1.25, pageHeight };
[pdfImage drawInRect: r
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0];
[pdfImage release]; pdfImage = nil;
rect.origin.y -= pageHeight;
}
[compositeImage unlockFocus];
NSData *imageData = [compositeImage TIFFRepresentation];
NSBitmapImageRep *imageRep = [NSBitmapImageRep
imageRepWithData:imageData];
NSDictionary *imageProps = [NSDictionary dictionaryWithObject:
[NSNumber numberWithFloat:0.9] forKey:NSImageInterlaced];
imageData = [imageRep representationUsingType:NSJPEGFileType
properties:imageProps];
[imageData writeToFile:@"/Users/devon/Desktop/out.jpg"
atomically:YES];
You can view images of the results here.
Any help would be fantastic!
Devon
_______________________________________________
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