I am trying convert the WKWebView content to image. It is working fine on any URL I load but when I try to get image of loaded PDF, it is giving blank grey image. Following are some of the methods that I have tried so far and also video links
WKWebView to image with PDF: https://drive.google.com/file/d/1xPNk10HEd-02YpXfH-NRpQzqT6mSQFRd/view?usp=sharing
WKWebView to image with site: https://drive.google.com/file/d/14YNqHYmDweMW8sE3SHvHIzLd2fOyko6l/view?usp=sharing
// Method 1
UIImage image;
UIGraphics.BeginImageContextWithOptions(webView1.Frame.Size, true, 0.0f);
webView1.DrawViewHierarchy(webView1.Bounds, afterScreenUpdates: true);
image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return image;
// Method 2
UIImage image;
UIGraphics.BeginImageContextWithOptions(webView1.Frame.Size, true, 0.0f);
webView1.Layer.RenderInContext(UIGraphics.GetCurrentContext());
image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return image;
// Method 3
UIImage image = null;
var config = new WKSnapshotConfiguration()
{
Rect = webView1.Bounds,
};
webView1.TakeSnapshot(config, (img, error) =>
{
if (error == null)
{
image = img;
AttachImageIntoMessage(image);
}
else
System.Diagnostics.Debug.WriteLine(error.ToString());
});
All of the above methods are working fine on simple links i.e. https://www.google.com but none of them are working when WKWebView is loaded with PDF i.e. https://blog.mozilla.org/security/files/2015/05/HTTPS-FAQ.pdf