Saving to TIFF

Under certain circumstances, you might want to generate a TIFF file instead of a PDF file. TIFF files can be displayed on Macs running Mac OS 9 and can be transferred to numerous applications on Windows- or Unix-based systems.

We’ll use the NSImage class to convert the PDF generated in the previous section into a TIFF representation. Then we’ll ask the NSImage instance to write its image, in TIFF format, to a second stream. This second stream will then be saved to the file that the user specifies.

  1. Insert the following TIFFForView: method declaration into Controller.h:

                         - (NSData *)TIFFForView:(NSView *)aView;
  2. Insert the following TIFFForView: method into Controller.m:

                         - (NSData *)TIFFForView:(NSView *)aView
                         {
                             NSImage *image = [[NSImage alloc] 
                                               initWithData:[self PDFForView:aView]];
                         
        [image autorelease];
                             return [image TIFFRepresentation];
                         }

Now that we have our TIFFForView: method to save in TIFF format, how should we invoke it? One way would be to create a second menu item — for example, “Save Graph as TIFF”. But a better (and more common) interface technique is to provide the user with file-format choices in the Save sheet. The way to do this is with an accessory view.

Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.