Export scrollview content shows only visible content not hidden content iOS swift

Problem:

I'm having an issue that only scrollview visible content's are exported but hidden contents are not exported.


 Solution:

You can solve that by using export contents in the scroll contentview then it will works good...

extension UIScrollView {

    // Export pdf from Save pdf in drectory and return pdf file path

    func exportAsPdfFromViews() -> String {

        let origSize = self.frame

        var newSize = origSize

        newSize.size = self.contentSize

        self.frame = newSize

        self.clipsToBounds = true

        self.layoutSubviews()

        self.layoutIfNeeded()


        let pdfPageBounds = CGRect(x:0, y: 0, width: self.contentSize.width, height:self.contentSize.height)

        let pdfPageFrame = pdfPageBounds

        let pdfData = NSMutableData()

        UIGraphicsBeginPDFContextToData(pdfData, pdfPageFrame, nil)

        UIGraphicsBeginPDFPage()

        guard let pdfContext = UIGraphicsGetCurrentContext() else { return "" }

        self.subviews[0].layer.render(in: pdfContext)

        UIGraphicsEndPDFContext()

        self.frame = origSize

        return self.saveViewPdf(data: pdfData)

    }

}

The above will be working fine 

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift