I have been stuck on this for quite sometime, I can’t seem to get it right. Page 1 is created but all other pages are blank, even worse is once I scroll to the bottom and create the pdf all the pages comes out blank. How do I go about solving this?
Hi and welcome to the forum community @wurllink! If you are referring to a tutorial please share the link so we can have a source to possibly look at or if you have any code to share that would be awesome.
Best,
Gina
Hi @gdelarosa, this is the code that I am currently using.
`
func createPDF() {
let scrollview = waiverViews.scrollView
let pageDimensions = scrollview.bounds
let pageSize = pageDimensions.size
let totalSize = scrollview.contentSize
let numberOfPagesThatFitVertically = Int(ceil(totalSize.height / pageSize.height))
let outputData = NSMutableData()
UIGraphicsBeginPDFContextToData(outputData, pageDimensions, nil)
let savedContentOffset = scrollview.contentOffset
let savedContentInset = scrollview.contentInset
scrollview.contentInset = UIEdgeInsets.zero
if let context = UIGraphicsGetCurrentContext() {
for indexVertical in 0 ..< numberOfPagesThatFitVertically {
UIGraphicsBeginPDFPage()
let offsetVertical = CGFloat(indexVertical) * pageSize.height
scrollview.contentOffset = CGPoint(x: 0, y: offsetVertical)
context.translateBy(x: 0, y: -offsetVertical)
scrollview.layer.render(in: context)
}
scrollview.contentInset = savedContentInset
scrollview.contentOffset = savedContentOffset
UIGraphicsEndPDFContext()
}
}
`
@wurllink Do you still have issues with this?
Yeah, I never found the solution so the project stopped at that point.
1 Like
@wurllink, Did you find the solution for this cause i am stuck now…