PDF Broken issue iOS 15.0

H i, I have used the PKCanvas view in my app. writing something in my PKCanvas View then convert it into a PDF. But adding the header for each page in PDF by using the following code,

  let printable:CGRect = CGRect(x: 0, y: 50, width: 595 , height: 841)

      render.setValue(NSValue(cgRect: page), forKey: "paperRect")       render.setValue(NSValue(cgRect: printable), forKey: "printableRect")       // 4. Create PDF context and draw       let pdfData = NSMutableData()       UIGraphicsBeginPDFContextToData(pdfData, CGRect(x:0,y:0,width: 595.2,height:841), nil)

      for i in 1...render.numberOfPages {           UIGraphicsBeginPDFPage();           let bounds = UIGraphicsGetPDFContextBounds()           render.drawPage(at: i-1, in: bounds)       }       UIGraphicsEndPDFContext();

But while renderer the PKCanvas View it was broken, I think PKCanvas view rendering is not properly working in iOS 15.0,15.0.1 and 15.0.2. I have attached the following screenshot,

There are many issues reported:

https://developer.apple.com/forums/thread/691512

Did it work in iOS 14 ? You should also file a bug report, that may speed up correction.

Note: you should use code formatter tool to present code.

In similar case, I add a prepare statement :

render.setValue(NSValue(cgRect: page), forKey: "paperRect")
render.setValue(NSValue(cgRect: printable), forKey: "printableRect")
// 4. Create PDF context and draw
let pdfData = NSMutableData()
render.prepare(forDrawingPages: NSMakeRange(0, render.numberOfPages))  // <<-- I ADD THIS
UIGraphicsBeginPDFContextToData(pdfData, CGRect(x:0,y:0,width: 595.2,height:841), nil)
for i in 1...render.numberOfPages {
    UIGraphicsBeginPDFPage()
    let bounds = UIGraphicsGetPDFContextBounds()
    render.drawPage(at: i-1, in: bounds)
}
UIGraphicsEndPDFContext();

Hi Claude, It's working fine in iOS 13.0, 14.0 . But not working on iOS 15.0,15.0.1, 15.0.2. I also add your's line ,

render.prepare(forDrawingPages: NSMakeRange(0, render.numberOfPages))

Still, it's breaking

PDF Broken issue iOS 15.0
 
 
Q