I'm updating an image resizing Mac App. What I want to be able to do is if the user imports an image to be resized that has a PDFImageRep, save a new PDF file with a resolution of my choosing.
So far I've tried to draw the image at a new size, as in:
- (NSImage*)imageAtSize:(NSSize)newSize
{
NSImage *resizedImage = [[NSImage alloc] initWithSize:newSize];
[resizedImage lockFocus];
[self drawInRect:NSMakeRect(0, 0, newSize.width, newSize.height)
fromRect:NSMakeRect(0, 0, self.size.width, self.size.height)
operation:NSCompositeSourceOver fraction:1.0];
[resizedImage unlockFocus];
return resizedImage;
}
but this loses the PDF image rep, and therefore makes my saving code fail.
- (void)saveAsPDFWithOutputDirectory:(NSURL *)outputDirectory size:(NSSize)newSize
{
NSPDFImageRep *pdfRep = [self PDFImageRep];
[pdfRep setSize:newSize];
NSError *error = nil;
[pdfRep.PDFRepresentation writeToURL:outputDirectory options:NSDataWritingAtomic error:&error];
if (error)
{
CLS_LOG(@"Error saving image: %@", error);
}
}
So how do I do it. The images I'm going to be using should be vector based, so is there some way I could just update a property on the PDF to specify a new resolution?