iclems / iOS-htmltopdf

MIT License
305 stars 79 forks source link

EXC_BAD_ACCESS #4

Closed SilentHunter124 closed 10 years ago

SilentHunter124 commented 11 years ago

It is generating a EXC_BAD_ACCESS Message when using your example:

libobjc.A.dylib`objc_msgSend:
0x17b708c:  movl   8(%esp), %ecx
0x17b7090:  movl   4(%esp), %eax
0x17b7094:  testl  %eax, %eax
0x17b7096:  je     0x17b70e8                 ; objc_msgSend + 92
0x17b7098:  movl   (%eax), %edx
0x17b709a:  pushl  %edi
0x17b709b:  movl   8(%edx), %edi

This is the code:

NSString *documentsDirectory = [NSHomeDirectory()
                                    stringByAppendingPathComponent:@"Documents"];

    NSString *filePath = [documentsDirectory
                          stringByAppendingPathComponent:@"demo.pdf"];
        _PDFCreator = [NDHTMLtoPDF createPDFWithHTML:[self generateHTMLforPDF] pathForPDF:filePath delegate:nil pageSize:kPaperSizeA4 margins:UIEdgeInsetsMake(10, 5, 10, 5)];
SilentHunter124 commented 11 years ago

Obviously I found a solution. Do the following

if(_PDFCreator == NULL)
_PDFCreator = [NDHTMLtoPDF createPDFWithHTML:html pathForPDF:filePath delegate:self pageSize:kPaperSizeA4 margins:UIEdgeInsetsMake(10, 5, 10, 5)];

And in BOTH delegate methods add:

_PDFCreator = NULL;