mitchcohen / 360iDev2019-PDFKit

4 stars 0 forks source link

PDF so big and crash #1

Open zuqiu123 opened 4 years ago

zuqiu123 commented 4 years ago
Hello, could you please tell me that the iPhone will crash if the PDF is over 
40M or larger after the annotation is embedded into the PDF? How to solve this problem
mitchcohen commented 4 years ago

Hi @zuqiu123. I just tried a 50MB PDF file in this sample app, on an iPad. There were no crashes. PDF files can be extremely complex, where one 40MB file can be far more complicated internally than another 40MB file. I suggest working with other files and/or simplifying the file in question if feasible. Good luck.

The writing of the file locked the main thread as that occurred, so that should really be moved to a background thread. If you’re using this code for anything, I suggest changing:

    self.pdfView?.document?.write(to: path)

to

    DispatchQueue.global(qos: .background).async {
        print("Writing starting now")
        self.pdfView?.document?.write(to: path) //We don't really need to write this here - just demo'ing code
        print("Writing complete")
    }

in func savePDF().

zuqiu123 commented 3 years ago

Thank you for your reply. We use mobile phones. When the memory consumption of mobile phones like iPhone6 exceeds 300M, they will crash,I will try the method you provided to test under