Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions

Question

4. Who should be invited to attend?

Answered: 1 week ago