Creating PDF from UIWebview App Fails

I want to convert UIWebview (height = 4224,width = 568)to pdf in order to send it by mail when I used the application below for the code that broke on this line ([self.reportWebView.layer renderInContext:UIGraphicsGetCurrentContext()]). Please give me some good suggestions. Thanks.

    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();
   }
+4
source share
1 answer

You are misinterpreting the context.

Instead

[self.reportWebView.layer UIGraphicsGetCurrentContext()];

try it

self.reportWebView.layer.renderInContext(UIGraphicsGetCurrentContext())
+1
source

Source: https://habr.com/ru/post/1616050/


All Articles