If I understand your problem, to center your PDF after rotating it to display it correctly on top, unfortunately CGAffineTransformMakeRotation not enough.
You can do:
webView.scalesPageToFit = true let scale = CGAffineTransformMakeScale(0.6, 0.6) let translate = CGAffineTransformMakeTranslation(webView.frame.origin.x, webView.frame.origin.y - webView.frame.size.height * 0.25) let transform = CGAffineTransformConcat(translate, scale); webView.transform = CGAffineTransformRotate(transform, CGFloat(M_PI_2))
And return from conversion:
webView.transform = CGAffineTransformIdentity
There is also another working method, but I do not recommend doing :
(Too long and too difficult to process the html page to make a rotation.)
install webView -> download responsive HTML page -> this flexible download HTML PDF page -> insert the following javascript into webView
func webViewDidFinishLoad(webView: UIWebView) { let js = "document.body.style.setProperty('-webkit-transform', 'rotate(-90deg)', null);" webView.stringByEvaluatingJavaScriptFromString(js) }
You can also check your JS and JSFiddle if you want.
source share