<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.3.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGPDFPage/getDrawingTransform(_:rect:rotate:preserveAspectRatio:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Graphics",
      "CoreGraphics"
    ],
    "preciseIdentifier" : "c:@F@CGPDFPageGetDrawingTransform"
  },
  "title" : "getDrawingTransform(_:rect:rotate:preserveAspectRatio:)"
}
-->

# getDrawingTransform(_:rect:rotate:preserveAspectRatio:)

Returns the affine transform that maps a box to a given rectangle on a PDF page.

```
func getDrawingTransform(_ box: CGPDFBox, rect: CGRect, rotate: Int32, preserveAspectRatio: Bool) -> CGAffineTransform
```

## Parameters

`box`

A constant that specifies the type of box. For possible values, see [`CGPDFBox`](/documentation/CoreGraphics/CGPDFBox).

`rect`

A Quartz rectangle.

`rotate`

An integer, that must be a multiple of `90`, that specifies the angle by which the specified rectangle is rotated clockwise.

`preserveAspectRatio`

A Boolean value that specifies whether or not the aspect ratio should be preserved. A value of <doc://com.apple.documentation/documentation/Swift/true> specifies that the aspect ratio should be preserved.

## Return Value

An affine transform that maps the box specified by the `box` parameter to the rectangle specified by the `rect` parameter.

## Discussion

Quartz constructs the affine transform as follows:

- Computes the effective rectangle by intersecting the rectangle associated with `box` and the `/MediaBox` entry of the specified page.
- Rotates the effective rectangle according to the page’s `/Rotate` entry.
- Centers the resulting rectangle on `rect`.If the value of the `rotate` parameter is non-zero, then the rectangle is rotated clockwise by rotate degrees. The value of `rotate` must be a multiple of 90.
- Scales the rectangle, if necessary, so that it coincides with the edges of `rect`. If the value of `preserveAspectRatio` parameter is <doc://com.apple.documentation/documentation/Swift/true>, then the final rectangle coincides with the edges of `rect` only in the more restrictive dimension.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)