[SOLVED] Printing problems with Cocoa

Discussion in 'Mac Programming' started by Eraserhead, Nov 4, 2007.

  1. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #1
    I have been trying to add printing to D&D Manager, so that you can print off information about the characters. I have created a view for printing, which seems to print fine except that half my labels are in the wrong place. The first attachment is the view in Interface Builder, and the second is the PDF "print".

    The Image from IB:
    Picture 1.png
    The Output:
    View attachment PDF Output.pdf

    The code I am using for printing in MyDocument.m is:

    Code:
    -(IBAction)printDocument:(id)sender{
    	[printInfo setOrientation:NSLandscapeOrientation];
    	//probably not do the following.
    	[printInfo setLeftMargin:36];//1.25cm
    	[printInfo setRightMargin:36];//1.25cm
    	[printInfo setTopMargin:28];//1cm
    	[printInfo setBottomMargin:28];//1cm
    	[self printDocumentWithSettings:[printInfo dictionary] showPrintPanel:YES delegate:self didPrintSelector:nil contextInfo:NULL];
    }
    - (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)printSettings error:(NSError **)outError{
    	if(quickPrint==nil){
    		quickPrint=[[QuickPrintController alloc] init];
    	}
    	NSManagedObject *obj=[[[appController characterController] selectedObjects] objectAtIndex:0];
    	//NSLog(@"character printing=%@",[obj valueForKey:@"name"]);
    	[quickPrint setSelectedCharacterToCharacter:obj];
    	NSPrintOperation *op=[quickPrint printOperation];
    	[op setPrintInfo:[[[NSPrintInfo alloc] initWithDictionary:printSettings] autorelease]];
    	return op;
    }
    
    QuickPrintController contains the printing view and the line:
    Code:
    return [NSPrintOperation printOperationWithView:quickPrintView];
    
    The full project can be downloaded here.

    I am using Xcode 3.0 on Mac OS X 10.5.0, but the issue seemed to occur even when I built my code on Tiger (10.4.10) with Xcode 2.4.
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    I didn't download the project, but the only reason I can think of that the form fields would be moving is because the autoresizing masks haven't been properly setup?
     
  3. thread starter macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #3
    That looks like the reason, they are different for the different elements, and given the new IB I didn't notice. Thanks :eek:.
     

Share This Page