Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "AppDelegate.h"
- @implementation AppDelegate
- @synthesize window = _window;
- @synthesize textView;
- @synthesize pageButton;
- - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
- {
- [pageButton setState:NSOffState];
- pageIt = FALSE;
- }
- - (IBAction)switchPage:(id)sender
- {
- if (pageIt)
- pageIt = FALSE;
- else
- pageIt = TRUE;
- NSLog(@"%d",pageIt);
- }
- - (IBAction)exportPDF:(id)sender
- {
- NSArray *ext = [NSArray arrayWithObjects: @"pdf",nil];
- NSSavePanel *panel = [NSSavePanel savePanel];
- [panel setAllowedFileTypes:ext];
- [panel beginSheetModalForWindow:_window
- completionHandler:^(NSInteger result) {
- if (result == NSOKButton){
- if (pageIt) {
- NSPrintInfo *printInfo;
- NSPrintInfo *sharedInfo;
- NSPrintOperation *printOp;
- NSMutableDictionary *printInfoDict;
- NSMutableDictionary *sharedDict;
- sharedInfo = [NSPrintInfo sharedPrintInfo];
- sharedDict = [sharedInfo dictionary];
- printInfoDict = [NSMutableDictionary dictionaryWithDictionary: sharedDict];
- [printInfoDict setObject:NSPrintSaveJob
- forKey:NSPrintJobDisposition];
- [printInfoDict setObject:[panel URL] forKey:NSPrintSavePath];
- printInfo = [[NSPrintInfo alloc] initWithDictionary:printInfoDict];
- [printInfo setHorizontalPagination: NSAutoPagination];
- [printInfo setVerticalPagination: NSAutoPagination];
- [printInfo setVerticallyCentered:NO];
- printOp = [NSPrintOperation printOperationWithView:textView
- printInfo:printInfo];
- [printOp setShowsProgressPanel:NO];
- [printOp runOperation];
- } else {
- NSRect r = [textView bounds];
- NSData *data = [textView dataWithPDFInsideRect:r];
- [data writeToURL:[panel URL] atomically:YES];
- }
- NSLog(@"We actually saved");
- NSURL *fileURL = [panel URL];
- NSString *saveName = [fileURL path];
- NSLog(@"Saved as filename = %@",saveName);
- } else {
- NSLog(@"Did not save");
- }
- }];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement