Created
February 14, 2017 05:36
-
-
Save jkmathew/33f7dd40a1d3adc5a4ba5fbcad14d1b3 to your computer and use it in GitHub Desktop.
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
//reference https://gist.github.com/tempire/0bd8cb78290aa9bc6adf | |
func addSignature(_ signature:UIImage, onPDFAt path: String) { | |
let pdf = CGPDFDocument(NSURL(fileURLWithPath: path))! | |
let pageCount = pdf.numberOfPages; | |
UIGraphicsBeginPDFContextToFile(path, CGRect.zero, nil) | |
for index in 1...pageCount { | |
let page = pdf.page(at: index)! | |
let pageFrame = page.getBoxRect(CGPDFBox.mediaBox) | |
UIGraphicsBeginPDFPageWithInfo(pageFrame, nil) | |
let ctx = UIGraphicsGetCurrentContext()! | |
ctx.saveGState(); | |
ctx.scaleBy(x: 1, y: -1); | |
ctx.translateBy(x: 0, y: -pageFrame.size.height); | |
ctx.drawPDFPage(page); | |
ctx.restoreGState(); | |
signature.draw(in: CGRect(x: 492, y: 652, width:100 , height: 100))//change accordingly | |
} | |
UIGraphicsEndPDFContext() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment