adding an NSPDFImageRep to an NSImage scales (down) image
adding an NSPDFImageRep to an NSImage scales (down) image
- Subject: adding an NSPDFImageRep to an NSImage scales (down) image
- From: Warwick Hall <email@hidden>
- Date: Fri, 25 May 2007 15:13:59 +1000
hello all,
i am attempting to generate a TIFF file from a page of a PDF document.
the image is created and saved to the file path i want, but it shrinks.
when i open the TIFF in Preview.app, and look at the Get Info... it
shows the correct image pixel size (w = 596, h = 842). but when
printed it scales to about 70%. (seems suspiciously like it may have
something to do with 72.0 pixels per inch?!?!)
i have created my code based on the python script (which does
basically the same thing) pdf2tiff.py by Dinu Gherman found at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/223320/index_txt
my question is: why is it scaling, and how do i stop it from scaling?
my code is below (see [convert] message).
thankx.
__ BEGIN CODE __
//
// GBPdFixDelegate.m
// pdfix
//
// Created by Warwick Hall on 23/05/07.
// Copyright 2007 GreenBoy Pty Ltd. All rights reserved.
//
#import "GBPdFixDelegate.h"
@implementation GBPdFixDelegate
- (void) convert
{
NSString * fileName = [[aCurrentSource path]
stringByDeletingPathExtension];
NSData * pdfData = [NSData dataWithContentsOfURL : aCurrentSource];
NSPDFImageRep * pdfImageRep = [NSPDFImageRep imageRepWithData :
pdfData];
int pageCount = [pdfImageRep pageCount];
int loop = 0;
for( loop = 0 ; loop < pageCount ; ++loop )
{
NSString * output = [NSString stringWithFormat : @"%@-%
03d.tiff", fileName, (loop + 1)];
[pdfImageRep setCurrentPage : loop];
NSImage * pdfImage = [[NSImage alloc] init];
[pdfImage addRepresentation : pdfImageRep];
NSSize theSize = [pdfImage size];
[pdfImage setScalesWhenResized : YES];
theSize.width = theSize.width * 72.0 / 72.0;
theSize.height = theSize.height * 72.0 / 72.0;
[pdfImage setSize : theSize];
NSData * tiffData = [pdfImage
TIFFRepresentationUsingCompression : NSTIFFCompressionCCITTFAX3
factor : 1.0];
[tiffData writeToFile : output atomically : YES];
[pdfImage release]; pdfImage = nil;
}
}
- (void) applicationDidFinishLaunching : (NSNotification *)iNotification
{
while( [self popSource] )
[self convert];
[NSApp terminate : self];
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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