sgr-ksmt / PDFGenerator

A simple generator of PDF written in Swift.
MIT License
757 stars 110 forks source link

InvalidContextError, cause? #56

Closed ChaosSaber closed 8 years ago

ChaosSaber commented 8 years ago

Hello it's me again,

recently began working again on my little project. Until now i only used the simulator and it worked fine. But now that i tested my project on an iPad, i get the InvalidContext Error. In the Apple Documentation (https://developer.apple.com/reference/uikit/1623918-uigraphicsgetcurrentcontext) is stated, that you have to push a context on the stack if not called from an UIView, which is my case. But this should be done with this line of Code UIGraphicsBeginPDFContextToFile(outputPath, .zero, password.toDocumentInfo()) which is called before

guard let context = UIGraphicsGetCurrentContext() else {
    throw PDFGenerateError.InvalidContext
}

So i'm a bit clueless at the moment what could be wrong and cause this error. I Hope you can help me with that and thanks in Advance

ChaosSaber commented 8 years ago

Ok i narrowed the problem down. UIGraphicsBeginPDFContextToFile()returns a boolean if successful or not. The problem is: it's unfortunately not successful. Tried to output it as data and then writing the data to a file. The Data could be created, but as soon as i want to write the data do a file i get an error: "Operation not permitted". Well time to find out why i'm not permitted to do it.

ChaosSaber commented 8 years ago

Problem completely solved. let dst = NSHomeDirectory().stringByAppendingString("/sample1.pdf") is in iOS the path to the app bundle, which can not be changed during runtime. i just need another save directory. i advice you add an disclaimer/ warning in your readme at these parts.