Question
I have a `UICollectionView` which scrolls through multiple pages. I want to put the entire collection view into PDF form, whereas now, all I get
I have a `UICollectionView` which scrolls through multiple pages. I want to put the entire collection view into PDF form, whereas now, all I get in PDF form is the part of the collection view that was last on the screen. The code is:
func createPdfFile() -> URL? { if let myView = myView { let pdfData = NSMutableData() UIGraphicsBeginPDFContextToData(pdfData, myView.bounds, nil) UIGraphicsBeginPDFPage() guard let pdfContext = UIGraphicsGetCurrentContext() else { return nil } myView.layer.render(in: pdfContext) UIGraphicsEndPDFContext() let fileName = "temp.pdf" let fileURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(fileName) if pdfData.write(to: fileURL, atomically: true) { print("Successfully wrote to \(fileURL)") return fileURL } else { return nil } } else { DLog("Error: Could not create pdf") return nil } } func printView() { if let fileURL = createPdfFile() { let webView = UIWebView() webView.loadRequest(URLRequest(url: fileURL)) self.view = webView } else { DLog("Error: Could not print the pdf. Write to disk failed.") alertOk("Failed to generate PDF.", title: "Error") } } How can I get it to render *all* of the view into a PDF?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started