4

I want to convert UIWebview (height = 4224,width = 568) into pdf to send it through mail,when I used below code app getting crashed in this line ([self.reportWebView.layer renderInContext:UIGraphicsGetCurrentContext()]). Please give me some good suggestions. Thank you.

    CGRect frame = self.reportWebView.frame;
    CGSize fittingSize = [self.reportWebView sizeThatFits:CGSizeZero];
    frame.size = fittingSize;
    self.reportWebView.frame = frame;

    NSMutableData *pdfData = [NSMutableData data];
    @autoreleasepool {
    // Points the pdf converter to the mutable data object and to the UIView to be converted
         UIGraphicsBeginPDFContextToData(pdfData, self.reportWebView.bounds, nil);
         UIGraphicsBeginPDFPage();
         [self.reportWebView.layer renderInContext:UIGraphicsGetCurrentContext()];
         UIGraphicsEndPDFContext();
   }
Infaz
  • 1,133
  • 9
  • 19

1 Answers1

1

You are rendering the context in a wrong way.

Instead of

[self.reportWebView.layer UIGraphicsGetCurrentContext()];

Try this

self.reportWebView.layer.renderInContext(UIGraphicsGetCurrentContext())
ipraba
  • 16,485
  • 4
  • 59
  • 58