我尝试找到在 xamarin.forms 上显示本地 pdf 文件的方法。我找到了一个实现 webview 及其渲染的自定义实现的解决方案:pdf 阅读器主要代码是:public class CustomWebView : WebView{ public static readonly BindableProperty UriProperty = BindableProperty.Create<CustomWebView, string>(p => p.Uri, default(string)); public string Uri { get { return (string)GetValue(UriProperty); } set { SetValue(UriProperty, value); } }}使成为:[assembly: ExportRenderer (typeof(CustomWebView), typeof(CustomWebViewRenderer))]namespace DisplayPDF.iOS{ public class CustomWebViewRenderer : ViewRenderer<CustomWebView, UIWebView> { protected override void OnElementChanged (ElementChangedEventArgs<CustomWebView> e) { base.OnElementChanged (e); if (Control == null) { SetNativeControl (new UIWebView ()); } if (e.OldElement != null) { // Cleanup } if (e.NewElement != null) { var customWebView = Element as CustomWebView; string fileName = Path.Combine (NSBundle.MainBundle.BundlePath, string.Format ("Content/{0}", WebUtility.UrlEncode (customWebView.Uri))); Control.LoadRequest (new NSUrlRequest (new NSUrl (fileName, false))); Control.ScalesPageToFit = true; } } }}还有我的页面:public class WebViewPageCS : ContentPage { public WebViewPageCS () { webView = new CustomWebView { Uri = "ScalaReference.pdf", HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; }但是现在我找不到像这篇文章中描述的那样向这个 pdf 文件添加锚点的方法:anchor to pdf我还尝试将此代码用于评估脚本:private async void Scroll_Clicked(object sender, EventArgs e){ webView.Eval($"window.scrollTo(0, {x});");}它适用于默认 webview,但不适用于自定义 webview。也许有人知道通过 xamarin.forms 将锚点滚动/设置为 pdf 并链接到该锚点的任何其他方法?谢谢你。
1 回答
- 1 回答
- 0 关注
- 126 浏览
添加回答
举报
0/150
提交
取消