“Chapter 2, Printing Concepts for Carbon Developers,” discussed the high-level tasks required to support printing in a Carbon application: setting up the page format, setting up the print settings, and printing the print job. This chapter shows you how to implement each of those tasks for a document-based Carbon application, such as a text editor or drawing application. This chapter describes the following tasks:
“Setting Up the Page Format.” Your application must make sure valid page format settings exist for a document.
“Setting Up the Print Settings.” Your application must make sure valid print settings exist for a print job.
“Printing the Job.” Your application must determine how many pages are in the print job and draw each page.
“Handling Errors.” Errors can occur at many points during the printing process. Your application should provide a function to post error messages, should they occur.
“Saving a Document as a PDF File.” Saving a document as a portable document format (PDF) file in Mac OS X uses code similar to the code you need to print a document to a printer. With very little effort on your part, your application can provide users with the ability to save their documents to a file that uses this popular format.
“Printing One Copy.” Your application can provide a shortcut command (Print One Copy) to allow users to print a single copy of a document using default settings without requiring them to open the Page Setup and Print dialogs.
“Printing Multiple Copies.” The printing system handles printing multiple copies for you.
This chapter contains sample code to illustrate each task you need to do to support printing. See Printing Carbon Sample Code for the sample application on which the code is based.
If you’ve installed the Mac OS X Developer Tools CD you can find additional sample applications in the following directory that show how to support printing in Mac OS X. You can compile and run the sample applications in Project Builder.
/Developer/Examples/Printing/App/
As you go through the sample code in this chapter, note that any function, data type, or constant your application must supply has the prefix My, except for global constants, which use the prefix gMy. Application-defined constants have the prefix kMy. Carbon Printing Manager functions use the prefix PM. If a line of code contains a commented number, an explanation for that line of code follows the listing.
Note: If your application has very simple printing needs and you are using Multilingual Text Engine (MLTE), you should investigate using the MLTE functions TXNPageSetup and TXNPrint instead of using Carbon Printing Manager functions. The MLTE functions call through to the Carbon Printing Manager, elminating the need for you to write the code described in this chapter.
Last updated: 2004-08-31