I am using the following code to convert HTML to PDF.
UIGraphicsBeginPDFContextToFile(self.filePath, CGRectZero, nil); //creating PDF
int i = 0;
for (; i < pages; i++)
{
if (pageHeight * (i+1) > height)
{
CGRect f = [myWebPage frame];
f.size.height -= (((i+1) * pageHeight) - height);
[myWebPage setFrame: f];
}
// Specify the size of the pdf page
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, width, pageHeight), nil);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
[[[myWebPage subviews] lastObject] setContentOffset:CGPointMake(0, pageHeight * i) animated:NO];
[myWebPage.layer renderInContext: currentContext];
NSLog(@"I = %d",i);
}
UIGraphicsEndPDFContext();
[[[myWebPage subviews] lastObject] setContentOffset:CGPointMake(0, 0) animated:NO];
[myWebPage setFrame:origframe];
but the loop is getting crashed after 10 second or for i >= 12,
its getting crashed at :
[myWebPage.layer renderInContext: currentContext];
i have tried with "CGContextRelease(currentContext);" also but its not working..
May I please know why is it crashing and how to prevent crashing of app.
Console output:
2013-06-06 10:15:26.179 app[8084:907] Width : 980.000000
2013-06-06 10:15:26.180 app[8084:907] NUMBER OF PAGES : 15
2013-06-06 10:15:26.382 app[8084:907] I = 0
2013-06-06 10:15:28.400 app[8084:907] I = 1
2013-06-06 10:15:28.903 app[8084:907] I = 2
2013-06-06 10:15:30.330 app[8084:907] I = 3
2013-06-06 10:15:31.524 app[8084:907] I = 4
2013-06-06 10:15:32.641 app[8084:907] I = 5
2013-06-06 10:15:33.470 app[8084:907] I = 6
2013-06-06 10:15:34.634 app[8084:907] I = 7
2013-06-06 10:15:35.791 app[8084:907] I = 8
2013-06-06 10:15:36.970 app[8084:907] I = 9
2013-06-06 10:15:38.108 app[8084:907] I = 10
2013-06-06 10:15:38.927 app[8084:907] I = 11
and app getting crashed in iPhone (Working properly in simulator )
(UPDATED) : and in other case its showing :
2013-06-06 11:17:33.023 app[8202:907] Width : 320.000000
2013-06-06 11:17:33.024 app[8202:907] NUMBER OF PAGES : 2
2013-06-06 11:17:38.200 app[8202:907] I = 0
2013-06-06 11:17:41.390 app[8202:907] I = 1
2013-06-06 11:17:44.028 app[8202:2103] void SendDelegateMessage(NSInvocation *): delegate (webView:didFinishLoadForFrame:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode
(lldb)
and
libsystem_kernel.dylib`mach_msg_trap:
0x3aa45e1c: mov r12, sp
0x3aa45e20: push {r4, r5, r6, r8}
0x3aa45e24: ldm r12, {r4, r5, r6}
0x3aa45e28: mvn r12, #30
0x3aa45e2c: svc #128
0x3aa45e30: pop {r4, r5, r6, r8} <=== Thread 1: singal SIGSTOP
0x3aa45e34: bx lr
Please help me out..