1

I've had some problem setting the size of the output image in the code below (which I found as an answer to another StackOverflow question).

I need to output the images as small previews and High Res images. But no matter what, it only outputs in 596 x 842.

I tried changing the size with the setSize method, but it only changes the size of the image, leaving a tiny image in a big blank space. I can't get it to scale properly.

Anyone has an idea?

NSPDFImageRep *img = [NSPDFImageRep imageRepWithContentsOfFile:pdfPath]; 
NSImage *temp = [[NSImage alloc] init]; 
NSBitmapImageRep *rep;

int count = [img pageCount]; 
for(int i = 0 ; i < count ; i++)
{ 
    [img setCurrentPage:i];
    [temp addRepresentation:img];      

    rep = [NSBitmapImageRep imageRepWithData:[temp TIFFRepresentation]];

    NSData *finalData = [rep representationUsingType:NSJPEGFileType properties:nil]; 
    NSString *pageName = [NSString stringWithFormat:@"%d.jpg", [img currentPage]]; 
    [fileManager createFileAtPath:[NSString stringWithFormat:@"%@/%@", localPath, pageName] contents:finalData attributes:nil];
}

Thanks in advance.

NOTE : This is a Mac OSX application.

Jer-o-nimo
  • 13
  • 3
  • Try UIImage, that always scales properly for me – Dustin Jun 29 '12 at 15:27
  • Hi! thanks for your comment. I use NSImage, because I'm developing for mac, not iOS. Should work too, though... I'll try some more, and keep you posted. – Jer-o-nimo Jun 30 '12 at 07:31

1 Answers1

0

It appears as though TIFFRepresentation will only ever return a 72dpi result, which is very low resolution.

I had the same problem and addressed it by rewriting the function to use the ImageIO framework. I had the PDF as the CGImageSource, and set JPG as the CGImageDestination. You can use CGImageProperties to specify the resolution, as well as many other things.

SentientAI
  • 401
  • 3
  • 8