UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Can someone please explain why I am only getting the contents of the visible view area rendered to the pdf

Forums > Swift

func renderPDF() {

    let containerView = waiverViews.containerView
    let pageDimensions = containerView.bounds
    let pageSize = CGRect(x: 0, y: 0, width: 612, height: 792)
    let pageCount = Int(ceilf(Float(pageDimensions.height / pageSize.height)))
    let outputData = NSMutableData()

    let pageRect = CGRect(x: 0, y: 20, width: 612, height: pageDimensions.height / 6)

    UIGraphicsBeginPDFContextToData(outputData, .zero, nil)

    if let context = UIGraphicsGetCurrentContext() {

        for i in 0...pageCount {

            let offset = CGFloat(i) * pageRect.width

            UIGraphicsBeginPDFPage()
            context.saveGState()
            context.translateBy(x: 0, y: -offset)
            context.scaleBy(x: 0.56, y: 0.56)
            containerView.layer.render(in: context)

            context.restoreGState()
        }
    }

    UIGraphicsEndPDFContext()
    savePdf(data: outputData)
}

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.