ios - Xamarin - iOS - WKWebView 快照不适用于加载的 PDF
问题描述
我正在尝试将 WKWebView 内容转换为图像。它在我加载的任何 URL 上都可以正常工作,但是当我尝试获取加载的 PDF 的图像时,它会给出空白的灰色图像。以下是我迄今为止尝试过的一些方法以及视频链接
WKWebView 到带有 PDF 的图像:https ://drive.google.com/file/d/1xPNk10HEd-02YpXfH-NRpQzqT6mSQFRd/view?usp=sharing
WKWebView 与站点的图像: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());
});
以上所有方法在简单链接上都可以正常工作,例如https://www.google.com,但是当 WKWebView 加载 PDF 时,它们都不起作用,例如https://blog.mozilla.org/security/files/2015/ 05/HTTPS-FAQ.pdf
解决方案
推荐阅读
- google-smart-home - 针对恒温器报告状态问题的 Google 智能家居操作
- javascript - 如何在渲染之前在实例上定义属性或方法
- html - 如何在 HTML 样式中包含 CSS 样式(通过 ASP.Net MVC Razor 页面生成的代码)
- laravel - 无效的道具:道具“活动”的类型检查失败。预期的布尔值,得到值为“true”的字符串
- php - 从 json_url 获取数据以及如何插入到我的 mysql 数据库
- visual-studio-code - 如何避免在vs代码中显示前导和尾随空格
- php - PHP - MySql:如何在 db 中存储来自 [输入文本] 和 [下拉值] 的值
- java - 无法弄清楚为什么此测试在向 ArrayList 添加项目时失败
- java - 如何在 java 8 中使用 IntStream 返回一个升序数组列表?
- python - python pandas按值计数重新标记值