     
 }
 
-extension UIView: PDFPageRenderable {    
-    fileprivate func _render<T: UIView>(_ view: T, scaleFactor: CGFloat, completion: (T) -> Void = { _ in }) throws {
+extension UIView: PDFPageRenderable {
+    fileprivate func _render<T: UIView>(_ view: T, scaleFactor: CGFloat, area: CGRect? = nil, completion: (T) -> Void = { _ in }) throws {
         guard scaleFactor > 0.0 else {
             throw PDFGenerateError.invalidScaleFactor
         }
         
-        let size = getPageSize()
+        let size: CGSize
+        let origin: CGPoint
+        if let area = area {
+            origin = area.origin
+            size = area.size
+        } else {
+            origin = .zero
+            size = getPageSize()
+        }
+        
         guard size.width > 0 && size.height > 0 else {
             throw PDFGenerateError.zeroSizeView(self)
         }

    }
    
    func renderPDFPage(scaleFactor: CGFloat) throws {
        func renderScrollView(_ scrollView: UIScrollView) throws {
            let tmp = scrollView.tempInfo
            scrollView.transformForRender()
            try _render(scrollView, scaleFactor: scaleFactor) { scrollView in
                scrollView.restore(tmp)
            }
        }
        
        if let webView = self as? UIWebView {
            try renderScrollView(webView.scrollView)
        } else if let webView = self as? WKWebView {
            try renderScrollView(webView.scrollView)
        } else if let scrollView = self as? UIScrollView {
            try renderScrollView(scrollView)
        } else {
            try _render(self, scaleFactor: scaleFactor)
        }
    }
    

            throw PDFGenerateError.invalidContext
        }

        let renderFrame = CGRect(origin: CGPoint(x: origin.x * scaleFactor, y: origin.y * scaleFactor),
                                 size: CGSize(width: size.width * scaleFactor, height: size.height * scaleFactor))
        autoreleasepool {
            let superView = view.superview
            view.removeFromSuperview()
            UIGraphicsBeginPDFPageWithInfo(CGRect(origin: .zero, size: renderFrame.size), nil)
            context.translateBy(x: -renderFrame.origin.x, y: -renderFrame.origin.y)
            view.layer.render(in: context)
            superView?.addSubview(view)
            superView?.layoutIfNeeded()
