PrOpenDoc
PrOpenDoc Initialize a GrafPort before printing a document
#include <PrintTraps.h> Printing Manager
TPPrPort PrOpenDoc(hPrtRec, pPrPort, pIOBuf );
THPrint hPrtRec ; handle leading to a TPrint structure
TPPrPort pPrPort ; address of a TPrPort structure; 0= allocate one
Ptr pIOBuf ; address of an I/O buffer; 0=allocate one
returns address of a TPrPort (a printing grafPort)
PrOpenDoc initializes a printing grafPort to be used in subsequent Print
Manager calls and makes it the active grafPort.
hPrtRec is a handle leading to a 120-byte TPrint structure. This should be a
valid printing record containing information set via PrStlDialog,
and PrJobDialog. Fields in the record are used in setting up the
grafPort and in deciding whether print spooling will be used.
pPrPort is the address of a 178-byte TPrPort record (whose first 108
bytes are a GrafPort). If pPrPort = 0, then the Printing Manager
automatically allocates such a structure as a nonrelocatable object on
the heap.
pIOBuf is the address of a 522-byte buffer to be used for I/O operations. If
pIOBuf = 0, then the volume buffer of the volume containing the
spool file is used (by default, the buffer of the current volume).
Returns: a TPrPort; the address of the printing grafPort to be used. If
pPrPort was non-zero on entry, that same address is returned.

Notes: Normal usage is to use NIL for both pPrPort and pIOBuf; e.g.:
TPrPort myPrtPort;
myPrtPort = PrOpenDoc( hPrtRec, 0,0 );
If you allocate the TPrPort yourself (e.g., to avoid fragmenting the heap),
don't waste time pre-setting any of its fields. It is completely initialized by
both PrOpenDoc and PrOpenPage.
The bJDocLoop field of the TPrint record determines whether printing will
be streamed to the printer or spooled to disk. This field is set by the Print
Manager dialogs and should NOT be changed by the caller.
The print record's prJob.pIdleProc is cleared to NIL by this call, so if you
want to perform any background task while printing (such as displaying the
current page number), you must set pIdleProc after calling both
Each call to PrOpenDoc must be balanced by a call to PrCloseDoc.
The following example assumes a valid TPrint record. Notice the call to
PrPicFile at the end of the example. You must use similar code to be able
to handle the common operation of spooled print files.
Example
#include <PrintTraps.h>
GrafPort myPrtPort;
short pgCnt, pgNum;
TPrStatus myPrStatus;
myPrtPort = PrOpenDoc( hPrtRec, 0,0 );
/* let system allocate port and IO buf */
pgCnt = MyPaginateDoc( ); [TOKEN:12074] user code to set page breaks */
(*hPrtRec)->prJob.pIdleProc=MyIdleProc; /* install bkgnd task ( optional)*/
/*...see PrPicFile for related info */
for (pgNum = 1; pgNum < pgCnt; pgNum++ ) { /* print all pages */
PrOpenPage( myPrtPort , 0 );
if ( PrError() ) { /* ...process the error... */}
MyDrawPage( pgNum ); /* use Quickdraw commands to draw */
if ( PrError() ) {/* ...process the error... */} /* check for error */
PrClosePage( myPrtPort );
}
PrCloseDoc( myPrtPort );
if ( (*hPrtRec)->prJob.bJDocLoop == bSpoolLoop ) {
MyMakeSomeRoom(); /* free up as much RAM as possible */
PrPicFile( hPrtRec, 0,0,0, &myPrStatus );
if ( PrError() ) {/* ...process the error... */}
}