---
title: "Drawing an upright stamp annotation on a rotated page"
canonical_url: "https://www.nutrient.io/guides/ios/knowledge-base/drawing-an-upright-stamp-annotation-on-a-rotated-page/"
md_url: "https://www.nutrient.io/guides/ios/knowledge-base/drawing-an-upright-stamp-annotation-on-a-rotated-page.md"
last_updated: "2026-05-25T18:42:17.763Z"
description: "When using a custom appearance stream generator to draw a stamp annotation, you’ll have to take care of the rotation offset of the page when drawing the image."
---

When using a [custom appearance stream generator](https://www.nutrient.io/api/ios/documentation/pspdfkit/annotation/appearancestreamgenerator) to draw a stamp annotation, you’ll have to take care of the rotation offset of the page when drawing the image.

Here’s sample code demonstrating the counter-rotation:

### SWIFT

```swift

func addUprightStampAnnotation () {
    // We need to fetch the `pageInfo` for the page in which the stamp annotation needs to be drawn.
    let pageInfo = document.pageInfoForPage(at: 0)

    // Here, we get the rotation of the page and convert it to radians.
    let rotation = CGFloat((pageInfo!.rotationOffset.rawValue + pageInfo!.savedRotation.rawValue) % 360) * CGFloat.pi / 180

    let image: UIImage = UIImage.init(named: "stamp-image")!
    let stampAnnotation = StampAnnotation()
    stampAnnotation.boundingBox = CGRect(x: 200, y: 200, width: 50, height: 50)

    let appearanceStreamGenerator = FileAppearanceStreamGenerator(fileURL: URL(fileURLWithPath: ""))
    appearanceStreamGenerator.drawingBlock = { context in
        var transform = CGAffineTransform.identity
        // First, translate and go to the center of the stamp annotation.
        transform = transform.translatedBy(x: stampAnnotation.boundingBox.origin.x + (stampAnnotation.boundingBox.size.width / 2),
                                           y: stampAnnotation.boundingBox.origin.y + (stampAnnotation.boundingBox.size.height / 2))
        // Now, rotate the context in the opposite direction of the page rotation.
        transform = transform.rotated(by: -1 * rotation)
        // Translate back to origin.
        transform = transform.translatedBy(x: -1 * (stampAnnotation.boundingBox.origin.x + (stampAnnotation.boundingBox.size.width / 2)),
                                           y: -1 * (stampAnnotation.boundingBox.origin.y + (stampAnnotation.boundingBox.size.height / 2)))
        context.concatenate(transform)
        // Draw the image now.
        context.draw(image.cgImage!, in: stampAnnotation.boundingBox)
    }
    stampAnnotation.appearanceStreamGenerator = appearanceStreamGenerator
    document.add(annotations: [stampAnnotation])
}

```

### OBJECTIVE-C

```objc

- (void)addUprightStampAnnotation {
    PSPDFDocument *document;
    // We need to fetch the `pageInfo` for the page in which the stamp annotation needs to be drawn.
    PSPDFPageInfo *pageInfo = [document pageInfoForPageAtIndex:0];

    // Here, we get the rotation of the page and convert it to radians.
    CGFloat rotationInDegrees =  (CGFloat)pageInfo.rotationOffset + (CGFloat)pageInfo.savedRotation;
    CGFloat rotation = rotationInDegrees * M_PI / 180;

    UIImage *image = [UIImage imageNamed:@"stamp-image"];
    PSPDFStampAnnotation *stampAnnotation = [[PSPDFStampAnnotation alloc] init];
    stampAnnotation.boundingBox = CGRectMake(200, 200, 50, 50);

    PSPDFFileAppearanceStreamGenerator *appearanceStreamGenerator = [[PSPDFFileAppearanceStreamGenerator alloc] initWithFileURL:[NSURL new]];
    [appearanceStreamGenerator setDrawingBlock:^(CGContextRef context) {
        CGAffineTransform transform = CGAffineTransformIdentity;

       // First, translate and go to the center of the stamp annotation.
        transform = CGAffineTransformTranslate(transform,
                                               stampAnnotation.boundingBox.origin.x + (stampAnnotation.boundingBox.size.width / 2),
                                               stampAnnotation.boundingBox.origin.y + (stampAnnotation.boundingBox.size.height / 2));

        // Now, rotate the context in the opposite direction of the page rotation.
        transform = CGAffineTransformRotate(transform, -1 * rotation);

        // Translate back to origin.
        transform = CGAffineTransformTranslate(transform,
                                               -1 * (stampAnnotation.boundingBox.origin.x + (stampAnnotation.boundingBox.size.width / 2)),
                                               -1 * (stampAnnotation.boundingBox.origin.y + (stampAnnotation.boundingBox.size.height / 2)));

        CGContextConcatCTM(context, transform);

        // Draw the image now.
        CGContextDrawImage(context, stampAnnotation.boundingBox, image.CGImage);
    }];

    stampAnnotation.appearanceStreamGenerator = appearanceStreamGenerator;
    [document addAnnotations:@[stampAnnotation] options:nil];
}

```
---

## Related pages

- [Adjusting Size Of Popovers](/guides/ios/knowledge-base/adjusting-size-of-popovers.md)
- [Customize PDF rendering on iOS](/guides/ios/knowledge-base/customize-document-rendering.md)
- [Adding Swipe Gesture Recognizer](/guides/ios/knowledge-base/adding-swipe-gesture-recognizer.md)
- [Adding Vector Image Annotation From Instant Json](/guides/ios/knowledge-base/adding-vector-image-annotation-from-instant-json.md)
- [Fix app store connect operation errors in Xcode](/guides/ios/knowledge-base/app-store-connect-operation-errors.md)
- [Archive Errors Cocoapods](/guides/ios/knowledge-base/archive-errors-cocoapods.md)
- [Configuring Scroll Views](/guides/ios/knowledge-base/configuring-scroll-views.md)
- [Customize Share Sheet Apps](/guides/ios/knowledge-base/customize-share-sheet-apps.md)
- [Debugging Issues](/guides/ios/knowledge-base/debugging-issues.md)
- [Customize your iOS navigation bar above crop UI](/guides/ios/knowledge-base/customize-the-navigation-bar-in-crop.md)
- [Customizing Annotation Toolbar Frame](/guides/ios/knowledge-base/customizing-annotation-toolbar-frame.md)
- [Disabling Adding Pages With Images](/guides/ios/knowledge-base/disabling-adding-pages-with-images.md)
- [Disabling Auto Opening Comments](/guides/ios/knowledge-base/disabling-auto-opening-comments.md)
- [Gatekeeper Alerts Mac Catalyst](/guides/ios/knowledge-base/gatekeeper-alerts-mac-catalyst.md)
- [Generate PDFs from complex HTML](/guides/ios/knowledge-base/generating-pdf-from-complex-html.md)
- [Disabling Text Selection](/guides/ios/knowledge-base/disabling-text-selection.md)
- [Disabling Directional Lock](/guides/ios/knowledge-base/disabling-directional-lock.md)
- [Adding a custom view controller in iOS](/guides/ios/knowledge-base/how-do-i-add-custom-controller-to-containerviewcontroller.md)
- [Customize action sheet appearance on iOS links](/guides/ios/knowledge-base/hide-or-customize-the-action-sheet-link-long-press.md)
- [How Do I Customize Search Results](/guides/ios/knowledge-base/how-do-i-customize-search-results.md)
- [How Do I Change How To Open Links](/guides/ios/knowledge-base/how-do-i-change-how-to-open-links.md)
- [How Do I Customize The Annotation Inspector](/guides/ios/knowledge-base/how-do-i-customize-the-annotation-inspector.md)
- [Capture ink signatures using SignatureViewController](/guides/ios/knowledge-base/how-do-i-get-an-image-from-signatureviewcontroller.md)
- [Other dependencies.](/guides/ios/knowledge-base/how-do-i-migrate-from-carthage-to-spm.md)
- [How Do I Download Pspdfkit As Fat Frameworks](/guides/ios/knowledge-base/how-do-i-download-pspdfkit-as-fat-frameworks.md)
- [Get notifications for unlocked password-protected PDFs](/guides/ios/knowledge-base/how-do-i-get-notified-when-a-password-protected-document-is-unlocked.md)
- [How Do I Present A Pspdftabbedviewcontroller In Cordova](/guides/ios/knowledge-base/how-do-i-present-a-pspdftabbedviewcontroller-in-cordova.md)
- [How Do I Migrate From Cocoapods To Spm](/guides/ios/knowledge-base/how-do-i-migrate-from-cocoapods-to-spm.md)
- [How Do I Select Or Deselect An Annotation Programmatically](/guides/ios/knowledge-base/how-do-i-select-or-deselect-an-annotation-programmatically.md)
- [Creating invisible digital signatures on iOS](/guides/ios/knowledge-base/invisible-signature.md)
- [How to add annotations programmatically in iOS](/guides/ios/knowledge-base/how-do-i-programmatically-add-annotation-to-the-saved-annotations-list.md)
- [How Do I Remove The Sign Arrow From The Signature Form Field](/guides/ios/knowledge-base/how-do-i-remove-the-sign-arrow-from-the-signature-form-field.md)
- [Fix incorrect page color in night appearance mode](/guides/ios/knowledge-base/how-do-i-reset-custom-document-render-options-before-change-the-appearance-mode.md)
- [Fixing library not found issues in iOS apps](/guides/ios/knowledge-base/library-not-found-swiftpm.md)
- [Processor Write To File Url](/guides/ios/knowledge-base/processor-write-to-file-url.md)
- [Block annotation editing and deletion in iOS](/guides/ios/knowledge-base/prevent-annotation-editing-allow-manipulation.md)
- [Search Special Characters](/guides/ios/knowledge-base/search-special-characters.md)
- [Showing Annotation Tools In The Main Toolbar](/guides/ios/knowledge-base/showing-annotation-tools-in-the-main-toolbar.md)
- [Separate Photo Library And Camera Actions](/guides/ios/knowledge-base/separate-photo-library-and-camera-actions.md)
- [How to store electronic signatures using Instant JSON](/guides/ios/knowledge-base/store-electronic-signatures-from-instant-json-annotations.md)
- [Setting The Initial Page Selection When Sharing](/guides/ios/knowledge-base/setting-the-initial-page-selection-when-sharing.md)
- [Suppressing File Coordination Alerts](/guides/ios/knowledge-base/suppressing-file-coordination-alerts.md)
- [Zoom to specific PDF annotations easily](/guides/ios/knowledge-base/zoom-to-specific-annotation.md)

