Printing in Mac Cocoa Programming
By: Aaron Hillegass
Code to handle printing is always relatively hard to write. Many factors are at play: pagination, margins, and page orientation, or landscape versus portrait.
Compared to most operating systems, Mac OS X makes writing print routines considerably easier. After all, your views already know how to generate PDF, and Mac OS X knows how to print PDF. If you have a document-based application and a view that knows how to draw itself, you simply implement printOperationWithSettings:error:. In this method, you create an NSPrintOperation object using a view and return it. The code, in your NSDocument subclass, would look like this:
- (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)ps
error:(NSError **)e;
{
NSPrintInfo *printInfo = [self printInfo];
NSPrintOperation *printOp
= [NSPrintOperation printOperationWithView:aView
printInfo:printInfo];
return printOp;
}
Archived Comments
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Listing of files in a tar file in Mac OS X.
Listing of files in a zip file in Mac OS X.
Multithreading versus Multiprocessing in Mac OS X.
Using NSOpenGLView in Cocoa Programming in Mac
Garbage Collector in Cocoa Programming in Mac
Weak References in Mac Cocoa Programming
Web Services in Mac Cocoa Programming
Printing in Mac Cocoa Programming
What is Cocoa? A brief history of Cocoa.
Programming Language used in Cocoa Programming
Objects, Classes, Methods, and Messages in Cocoa Programming