I have a PDF view created using PDFKIT which loads a PDF in iPad. When we zoom the PDF and make some freehand drawing it crashes. What could the problem be ??
Asked
Active
Viewed 702 times
2
-
Add an exception breakpoint and try to replicate crash. If you find one, update your answer with crash log. – manishsharma93 Jul 24 '19 at 11:43
-
I'm definitely seeing this issue, as well. Even if I save the file to disk and reopen it fresh, zooming in with ink annotations causes a crash due to memory consumption. According to the allocations instrument, zooming drastically increases the memory size of the IOSurface elements associated with annotations. This may be an issue internal to PDFKit and hopefully things will improve with iOS 13, but I haven't investigated, yet. – adamup Jul 24 '19 at 16:37
1 Answers
0
I had a similar issue where zooming in on a document with more than a few PDFAnnotations of subtype .ink would cause memory usage to quickly peak and my app to crash. At the time, I initiated each of my drawing annotations with the PDF page bounds like this:
let inkAnnotation = PDFAnnotation(bounds: page.bounds(for: pdfView.displayBox), forType: .ink, withProperties: nil)
What solved my problem and got rid of my performance issues was to initiate the PDFAnnotation with the bounding box of the UIBezierPath that represents the drawing on the page, instead of initiating it with the bounds of the entire PDF page.
let inkAnnotation = PDFAnnotation(bounds: bezierPath.bounds, forType: .ink, withProperties: nil)
Just make sure the bezier path bounds are correctly transformed in relation to your PDF page. This guide by Artem Poluektov might be a good starting point.