Hey everyone,
I am trying to generate a dynamically long multi-page PDF from a WKWebView with .createPDF() but the frame does not seem to make much of a difference.
Here's what I'm doing: I create the WKWebView with an A4-width and correctly calculate the height of said View, then I split up that height into A4 heights and round it up.
So let's say I get two pages.
I take that view and create frames from it with A4PageHeight*PageNumber so I get the correct starting heights of 0 for page one, 595.0 for page two etc.
Then I try to capture these frames to split up my document into multiple pages, combine them to a document and voilà. Here's the problem.
It doesn't matter the starting height value, every capture always contains the entire Page, no matter what I do. I thought the frame would capture just a part of the page.
public func createPDFPage(pageNumber: Int, totalNumber: Int) {
    numberOfPages = totalNumber
    let webConfiguration = WKWebViewConfiguration()
    let startHeight = CGFloat(pageNumber) * A4PageHeight
    let pageWidth = A4PageWidth
    let size = CGRect(x: 0, y: startHeight, width: pageWidth, height: A4PageHeight)
    let webView = WKWebView(frame: size, configuration: webConfiguration)
    webView.loadHTMLString(htmlString, baseURL: Bundle.main.resourceURL)
    let seconds = 2.0
    DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
        webView.createPDF(completionHandler: successCompletionHandler)
    }
}
Results in 3 pages that look like this:
Expected Output would have looked like this: