Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Environment and Utilities /
Chapter 7 - QuickDraw GX Stream Format / Using QuickDraw GX Stream Format


Obtaining Data From a Print File

Any suitably equipped Macintosh computer with QuickDraw GX installed can read and print portable digital document print files created by your application. You may want to use the public data in a QuickDraw GX print file for other purposes. Listing 7-11 reads a portable digital document print file and returns the page count. For more information on print files and portable digital documents, see the chapters "Introduction to QuickDraw GX Printing" and "Core Printing Features" of Inside Macintosh: QuickDraw GX Printing.

Listing 7-11 Obtaining the page count from a portable digital document print file

#define nrequire( x, LABEL ) if((x)) goto LABEL
   
/* Returns the page count from an open print file */
   
   Parameters:-> short dataRefNum:reference to the spool file
                    <- long *pageCount:returns page count
   Returns:    OSErr
   Preconditions:dataRefNum != NULL
   Postconditions:none */

OSErr DespoolPageCount (short dataRefNum, long *pageCount);
OSErr DespoolPageCount (short dataRefNum, long *pageCount) {

   register OSErr anErr;
            long pageDirOffset, numPages;
            long dataLen;
/* position to read offset to page directory */
   anErr = SetFPos(dataRefNum, fsFromStart, (long) (kHeaderSize + 
sizeof(long)));
   nrequire (anErr, SetPageDirOffsetPos);
   
   /* read offset to page directory */
   dataLen = sizeof(pageDirOffset);
   anErr = FSRead(dataRefNum, &dataLen, &pageDirOffset);
   nrequire (anErr, ReadPageDirOffsetPos);
   
/* move to page directory */
   anErr = SetFPos(dataRefNum, fsFromStart, (long) (pageDirOffset));
   nrequire (anErr, SetPageDirPos);
   
/* read number of pages */
   dataLen = sizeof(numPages);
   anErr = FSRead(dataRefNum, &dataLen, &numPages);
   nrequire (anErr, ReadNumPages);
   
   *pageCount = numPages;/* Return the result */
   
   ncheck (anErr);
   return anErr;

/* exception handling*/
ReadNumPages:
SetPageDirPos:
ReadPageDirOffsetPos:
SetPageDirOffsetPos:
   return anErr;
}

Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996