< Previous PageNext Page > Hide TOC

PostScript Conversion

The Preview application (in Mac OS X v10.3 and later) automatically converts PostScript files to PDF. The Quartz 2D API provides functions you can use to perform PostScript conversion in your application, as long as it runs in Mac OS X v10.3 and later.

Follow these steps to convert a PostScript document to a PDF document:

  1. Write callbacks. Quartz communicates the status of per page processes through callbacks.

  2. Fill a callbacks structure.

  3. Create a PostScript converter object.

  4. Create a data provider object for the PostScript file you want to convert.

  5. Create a data consumer object for the PDF that results from the conversion.

  6. Perform the conversion.

Each of these steps is discussed in the sections that follow.

In this section:

Writing Callbacks
Filling a Callbacks Structure
Creating a PostScript Converter Object
Creating Data Provider and Data Consumer Objects
Performing the Conversion


Writing Callbacks

Callbacks provide a way for Quartz to inform your application of the status of the conversion. If your application has a user interface, you can use the status information for provide feedback to the user, as shown in Figure 15-1.


Figure 15-1  A status message for a PostScript conversion application

A status message for a PostScript conversion application

You can provide callbacks to inform your application that Quartz 2D is:

See the CGPSConverter documentation in Quartz 2D Reference Collection for the prototype each callback follows.

Filling a Callbacks Structure

You need to assign a version number and the callbacks you created to the appropriate fields of the CGPSConverterCallbacks data structure (shown in Listing 15-1). The version is 0. Assign NULL to those fields for which you do not supply a callback.

Listing 15-1  The PostScript converter callbacks data structure

struct CGPSConverterCallbacks {
   unsigned int version;
   CGPSConverterBeginDocumentCallback beginDocument;
   CGPSConverterEndDocumentCallback endDocument;
   CGPSConverterBeginPageCallback beginPage;
   CGPSConverterEndPageCallback endPage;
   CGPSConverterProgressCallback noteProgress;
   CGPSConverterMessageCallback noteMessage;
   CGPSConverterReleaseInfoCallback releaseInfo;
};

Creating a PostScript Converter Object

You call the function CGPSConverterCreate to create a PostScript converter object. This function takes three parameters:

Important: Although the CGPSConverterConvert function is thread safe (it uses locks to prevent more than one conversion at a time in the same process), it is not thread safe with respect to the Resource Manager. If your application uses the Resource Manager on a separate thread, you should either use locks to prevent CGPSConverterConvert from executing during your usage of the Resource Manager or you should perform your conversions using the PostScript converter in a separate process.

Creating Data Provider and Data Consumer Objects

You create a data provider object by calling the function CGDataProviderCreateWithURL, supplying a CFURL object that specifies the address of the PostScript file you want to convert.

Similarly, you create a data consumer object by calling the function CGDataConsumerCreateWithURL, supplying a CFURL object that specifies the address of the PDF document that results from the conversion.

Performing the Conversion

You call the function CGPSConverterConvert to perform the actual conversion from PostScript to PDF. This function takes as parameters:

The function returns true if the conversion is successful.

In Mac OS X v10.4 and later, at any time, you can call the function CGPSConverterIsConverting to check whether the conversion is still progressing.



< Previous PageNext Page > Hide TOC


© 2001, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-12-11)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.