Created
December 6, 2024 17:21
-
-
Save kmithi1-apps/02eb54ebf1dfaa1cced35f18ed246fdb to your computer and use it in GitHub Desktop.
Add stamp annotation to PDF page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PDFImageAnnotation: PDFAnnotation { | |
var image: UIImage? | |
convenience init(_ image: UIImage?, bounds: CGRect, properties: [AnyHashable : Any]?) { | |
self.init(bounds: bounds, forType: PDFAnnotationSubtype.stamp, withProperties: properties) | |
self.image = image | |
} | |
override func draw(with box: PDFDisplayBox, in context: CGContext) { | |
super.draw(with: box, in: context) | |
guard let cgImage = image?.cgImage else { return } | |
context.draw(cgImage, in: bounds) | |
} | |
} | |
// add annotation | |
let image = UIImage(named: "myLogo") | |
let imageAnnotation = PDFImageAnnotation(image, bounds: CGRect(x: 200, y: 200, width: 200, height: 200), properties: nil) | |
page.addAnnotation(imageAnnotation) // Note make sure this in memory page object is not shared among multiple document |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment