Objective-C Issues with UIWebView to PDF

前端 未结 2 1569
日久生厌
日久生厌 2021-01-05 15:52

I have this method here that takes my UIWebView and convert into a PDF and its working well. But when I print off this PDF or email it, its cut off. Its like its only genera

2条回答
  •  梦谈多话
    2021-01-05 16:52

    In order to create your PDF file in memory, you need to draw the layer of the UIWebBrowserView instance that lies underneath the UIWebView's scrollView. In order to do that, try changing your renderInContext: call the following way :

    UIView* contentView = webViewPDF.scrollView.subviews.firstObject;
    [contentView.layer renderInContext:currentContext];
    

    Also, if you target iOS >= 7.0, then you can avoid using renderInContext: and use one of the snapshotViewAfterScreenUpdates: or drawViewHierarchyInRect:afterScreenUpdates: methods.

提交回复
热议问题