---
title: "PMSessionGetCGGraphicsContext(_:_:)"
framework: applicationservices
role: symbol
role_heading: Function
path: applicationservices/1461952-pmsessiongetcggraphicscontext
---

# PMSessionGetCGGraphicsContext(_:_:)

Obtains the Quartz graphics context for the current page in a printing session.

## Declaration

```swift
func PMSessionGetCGGraphicsContext(_ printSession: PMPrintSession, _ context: UnsafeMutablePointer<Unmanaged<CGContext>?>) -> OSStatus
```

## Parameters

- `printSession`: The printing session whose Quartz graphics context you want to obtain.
- `context`: A pointer to your doc://com.apple.coregraphics/documentation/CoreGraphics/CGContext variable. On return, the variable refers to the Quartz graphics context for the current page in the specified printing session. The context’s origin is at the lower-left corner of the sheet of paper, not the imageable area. You should not release the context without first retaining it. The context is valid only for the current page; you should not retain it beyond the end of the page.

## Return Value

Return Value A result code. See Result Codes.

## Discussion

Discussion If you’re using Quartz 2D to draw the content for a print job, after each call to PMSessionBeginPage you should call PMSessionGetCGGraphicsContext to obtain the Quartz graphics context for the current page. Note that before you can use the function PMSessionGetCGGraphicsContext, you must have called PMSessionBeginCGDocument or PMSessionBeginCGDocumentNoDialog(_:_:_:) instead of PMSessionBeginDocument or PMSessionBeginDocumentNoDialog.

## See Also

### Accessing Data in Printing Session Objects

- [PMSessionGetDataFromSession(_:_:_:)](applicationservices/1462964-pmsessiongetdatafromsession.md)
- [PMSessionSetDataInSession(_:_:_:)](applicationservices/1461902-pmsessionsetdatainsession.md)
- [PMSessionGetCurrentPrinter(_:_:)](applicationservices/1458998-pmsessiongetcurrentprinter.md)
- [PMSessionSetCurrentPMPrinter(_:_:)](applicationservices/1461096-pmsessionsetcurrentpmprinter.md)
- [PMSessionError(_:)](applicationservices/1460003-pmsessionerror.md)
- [PMSessionSetError(_:_:)](applicationservices/1460216-pmsessionseterror.md)
